Repository navigation
date: parse a trailing zone abbreviation in its own zone - #16148
unsound-mint wants to merge 1 commit into
Conversation
b2399e0 to
0bdb3bd
Compare
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
| // Parse in the target timezone so "10:30 EDT" means 10:30 in EDT. Parsing | ||
| // against the local `now` would move a wall-clock time that falls into a | ||
| // local DST gap forward before the abbreviation is applied. | ||
| let now_in_tz = now.with_time_zone(tz.clone()); |
There was a problem hiding this comment.
this also changes the default date: with TZ=Asia/Tokyo at 08:00, -d '10:30 UTC' now gets yesterday's date (it's still the previous day in UTC).
GNU takes the date from local time. Could you use now.datetime().to_zoned(tz.clone()) instead, to keep the local wall clock?
There was a problem hiding this comment.
Done: the default date now comes from now.datetime().to_zoned(tz), so -d '10:30 UTC' under TZ=Asia/Tokyo keeps the local date, same as GNU.
| fn test_date_abbreviation_in_local_dst_gap() { | ||
| // 02:30 does not exist in America/New_York on 2024-03-10, but the input | ||
| // names GMT, so the local DST rules must not shift it. | ||
| for input in ["Sun, 10 Mar 2024 02:30:00 GMT", "2024-03-10 02:30:00 UTC"] { |
There was a problem hiding this comment.
could you please also add the relative case from the issue, e.g. 2024-03-09 12:00 24 hours GMT?
There was a problem hiding this comment.
also, can you use rstest?
There was a problem hiding this comment.
Added 2024-03-09 12:00 24 hours GMT, and the cases are now rstest cases.
0bdb3bd to
e26684d
Compare
| if zoned.time_zone() != now_in_tz.time_zone() { | ||
| return None; | ||
| } | ||
|
|
There was a problem hiding this comment.
this comment is now stale: the comparison is against now_in_tz, not now
e26684d to
ee1d3ab
Compare
|
@unsound-mint nice, can you use rstest in your PR? |
ee1d3ab to
2d68b89
Compare
|
GNU testsuite comparison: |
| #[rstest] | ||
| #[case::rfc2822_gmt("Sun, 10 Mar 2024 02:30:00 GMT", "1710037800\n")] | ||
| #[case::iso_utc("2024-03-10 02:30:00 UTC", "1710037800\n")] | ||
| #[case::relative_hours("2024-03-09 12:00 24 hours GMT", "1710072000\n")] |
There was a problem hiding this comment.
could you please also add the other direction from the issue, 2024-03-10 04:00 2 hours ago GMT?
There was a problem hiding this comment.
Added 2024-03-10 04:00 2 hours ago GMT (1710036000), plus the fall-back case from the issue and -f under Europe/Berlin.
try_parse_with_abbreviation() split off the abbreviation and parsed the
rest against `now` in the local zone. A wall-clock time that falls into a
local DST gap was therefore moved forward an hour before the abbreviation
was applied, so e.g. with TZ=America/New_York,
`date -d "Sun, 10 Mar 2024 02:30:00 GMT" +%s` printed 03:30 GMT. Relative
hour items were counted on the local time line too.
Parse against `now`'s local date and time placed in the abbreviation's
zone instead, which is what the existing comment says the code does. The
default date still comes from local time, as in GNU.
The zone-mismatch check now compares against the abbreviation's zone, so
an offset glued to the time ("12:00-0500 EST") no longer looks like the
abbreviation's own zone; detect it by an odd number of '-' in a word.
Refs uutils#15772
2d68b89 to
ef01a0d
Compare
TZ=America/New_York date -d 'Sun, 10 Mar 2024 02:30:00 GMT' +%sprints 1710041400 (03:30 GMT) instead of 1710037800. 02:30 doesn't exist in New York that day, andtry_parse_with_abbreviation()parsed the time against the localnowbefore applying GMT, so the local DST rule moved it forward an hour. Relative hour items (24 hours,2 hours ago) were counted on the local time line as well.It now parses against
now's local date and time placed in the abbreviation's zone, so the default date still comes from local time as in GNU. Because the mismatch check now compares against the abbreviation's zone,names_zonealso counts a word with an odd number of-(12:00-0500 EST,12-0500 EST), which GNU rejects.Tests: gap and relative cases (including
2 hours agoand a fall-back crossing) underTZ=America/New_York,-funderEurope/Berlin, and the two rejections.One result differs from GNU, as the issue notes:
2024-03-09 02:30:00 1 day GMTunderTZ=America/New_Yorknow gives 1710037800 (02:30 GMT). GNU 9.10 applies day units in local time and gives 1710041400.Not covered here, because the zone is resolved inside the
parse_datetimecrate and not in this function:2024-03-10T02:30:00Z,Sun Mar 10 02:30:00 UTC 2024andtouch -d. They are the subject of uutils/parse_datetime#346. I built coreutils against that branch and all three give 1710037800 there, same as GNU. That is why this saysRefsand notCloses.