chronotope / chrono

Date and time library for Rust
Other
3.3k stars 523 forks source link

Convert `DateTime::with_nanosecond` to return `Result` #1520

Closed pitdicker closed 6 months ago

pitdicker commented 6 months ago

As I see it DateTime::with_nanosecond is one of the few methods on DateTime that does not need to return an error from the TimeZone trait and does not need to return a MappedLocalTime.

We assume in some places, like the platform code of Local, that time zone transitions happen on second boundaries. That seems entirely reasonable to me and fits with reality. There is also some similarity to how we assume offsets to be a round number of seconds from UTC.

In the IANA time zone database there are some time zone offsets from the 19th century that have an offset with fractional seconds. Those are based on the longitude of a city or mean of the country. The fractional part is included with a comment, and the shipped data uses round seconds. Necessarily if anyone takes those fractional offsets serious, they would need a transitions at a fractional second at some point when the country aligns from local mean time to round offsets from UTC.

If we assume there are no subsecond transitions DateTime::with_nanosecond can just assume the entire second has the same offset from UTC.

codecov[bot] commented 6 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 94.01%. Comparing base (d286f93) to head (7c53bd5).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## 0.5.x #1520 +/- ## ======================================= Coverage 94.01% 94.01% ======================================= Files 37 37 Lines 16830 16834 +4 ======================================= + Hits 15823 15827 +4 Misses 1007 1007 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.