Kotlin / kotlinx-datetime

KotlinX multiplatform date/time library
Apache License 2.0
2.43k stars 102 forks source link

Inconsistent behavior for dates on the edges of time overlaps #403

Closed dkhalanskyjb closed 4 months ago

dkhalanskyjb commented 4 months ago

A time overlap is when one clock reading occurs in several instants. For example, in New York, on 2023-11-05T02:00, clocks are shifted to 2023-11-05:01:00, so 2023-11-05T01:15 occurs twice.

The question is, does 2023-11-05T02:00 occur twice in New York? Our own system does not provide a consistent answer. Whenever we are querying historical data, the answer is no, 2023-11-05T02:00 only exists after the overlap. However, when querying the recurring rules, 2023-11-05T02:00 is considered to exist twice: just before the clocks shifted and after the time overlap.

If we treat TimeZone as a reified function (Instant) -> LocalDateTime, the answer is clear: since only one Instant maps to 2023-11-05T02:00 in New York, this local date-time is not in an overlap, so the behavior of the recurring rules should be fixed.