Repository navigation
fix(builder): handle wall-clock times in a DST gap like GNU date - #346
jayhemnani9910 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
Merging this PR will degrade performance by 4.62%3 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #346 +/- ##
=======================================
Coverage 98.97% 98.98%
=======================================
Files 21 21
Lines 4698 4716 +18
Branches 143 144 +1
=======================================
+ Hits 4650 4668 +18
Misses 47 47
Partials 1 1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| let (offset, hour_adjustment) = offset.normalize(); | ||
| dt = dt.checked_add(Span::new().hours(hour_adjustment))?; | ||
| dt = dt.datetime().to_zoned((&offset).try_into()?)?; | ||
| if need_midnight { |
There was a problem hiding this comment.
when need_midnight is false there is no date/time/weekday, so wanted == dt.datetime() here
both branches do the same thing, just keep the wanted one, no?
|
|
||
| // A date or time that names a moment the time zone skips does not | ||
| // exist; jiff would move it past the gap. | ||
| if need_midnight && !fixed_offset && dt.datetime() != wanted { |
There was a problem hiding this comment.
a date or a time already implies need_midnight, is this part of the condition needed?
| // A date or time that names a moment the time zone skips does not | ||
| // exist; jiff would move it past the gap. | ||
| if need_midnight && !fixed_offset && dt.datetime() != wanted { | ||
| return Err("invalid date: the local time does not exist in this time zone".into()); |
There was a problem hiding this comment.
the other errors don't have an "invalid date:" prefix, and coreutils already prints invalid date '...'
maybe just "local time does not exist in this time zone"?
| #[case::z( | ||
| r#"TZ="America/New_York" 2024-03-10T02:30:00Z"#, | ||
| "2024-03-10 02:30:00+00:00" | ||
| )] |
There was a problem hiding this comment.
please also add 2024-03-10 02:30 +00:00 (already right but not tested) and 02:30Z without the T, they are both in the description
|
All four in 3ceb7bc:
|
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
A date or time that falls in the local zone's DST gap was moved past the
gap by jiff (2024-03-10 02:30 in New York became 03:30). GNU date
rejects it as an invalid date, so do the same. A time written with its
own zone ("2024-03-10 02:30 UTC", "...T02:30:00Z") was built in the
local zone first and so came out an hour late; apply the zone to the
wall-clock time as written. A relative item that lands in a gap still
moves past it, as in GNU.
Without a date, time or weekday the wanted wall-clock time is the base's, so the need_midnight checks change nothing. Shorten the error message and test 02:30Z and 02:30 +00:00 in the gap.
3ceb7bc to
07e99b4
Compare
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
|
On the CodSpeed flags: none of the 4 inputs has an offset ( Local
Run-to-run noise is about ±5% here. What's left looks like a 2-5% cost from checking for the DST gap on local times, which I think is worth it for correct results. Happy to try a cheaper check if you'd rather not take it. |
Two problems with times in a DST gap (New York skips 02:00-03:00 on 2024-03-10):
The first is a time that doesn't exist; jiff's default disambiguation moves it past the gap, and GNU rejects it. The second is wrong by an hour: the date and time are first placed in the local zone, where 02:30 doesn't exist and becomes 03:30, and only then is the written zone applied to that wall clock.
02:30ZandT02:30:00Zare affected too;02:30 +00:00was already right because the time's own offset is applied first.build_in_rangenow keeps the wall-clock time the input asked for. If the local zone moved it, the input named a time in a gap and is rejected. If the input carries a zone (UTC,Z, an offset), that zone is applied to the requested wall-clock time instead of the locally resolved one. A relative item that lands in a gap (2018-11-03 +1 dayin Sao Paulo) still moves past it, as GNU does, and times in the repeated hour still take the first offset.Tests:
test_local_time_in_dst_gap_is_invalid,test_dst_gap_neighboursandtest_relative_item_moves_past_dst_gapintests/date.rs; 5 of the 9 cases fail on main.cargo test: 491 passed; clippy and fmt clean. 22 inputs in 6 zones (New York, Sao Paulo, Berlin, Lord Howe, Kolkata, UTC), covering gaps, the repeated hour, written zones and offsets, weekdays and relative items, give the same instant or error as GNU date 9.7.