The to_offset function can panic if timezone conversion shifts a date outside of the valid range. As dates are often sourced from outside sources and programs should avoid panics, it would be useful to have a checked variant that returns an option.
Currently the only option is to perform the conversion manually by turning the OffsetDateTime into a PrimitiveDateTime, the Offsets through seconds into a Duration and using the checked_sub and checked_add methods before reassembling an OffsetDateTime.
While I no longer personally have a use case for to_offset, I originally planed to use it to convert parsed dates into UTC to allow for faster comparisons, although I suppose that if comparison speed ever truly becomes an issue I should just switch to timestamps instead. Nevertheless, I still think a fallible version of to_offset could be useful in the future.
The
to_offset
function can panic if timezone conversion shifts a date outside of the valid range. As dates are often sourced from outside sources and programs should avoid panics, it would be useful to have a checked variant that returns an option.Currently the only option is to perform the conversion manually by turning the
OffsetDateTime
into aPrimitiveDateTime
, theOffset
s through seconds into aDuration
and using thechecked_sub
andchecked_add
methods before reassembling anOffsetDateTime
.While I no longer personally have a use case for
to_offset
, I originally planed to use it to convert parsed dates into UTC to allow for faster comparisons, although I suppose that if comparison speed ever truly becomes an issue I should just switch to timestamps instead. Nevertheless, I still think a fallible version ofto_offset
could be useful in the future.