Repository navigation
Conversation
Merging this PR will not alter performance1 warning, 1 note
Comparing Footnotes
|
| let has_local_tz_abbrev = local_tz_rewritten.is_some(); | ||
| let parse_input = local_tz_rewritten.as_deref().unwrap_or(normalized.as_ref()); | ||
|
|
||
| // First, try to parse any non-local trailing timezone abbreviations |
There was a problem hiding this comment.
with this, the local zone check at the end of try_parse_with_abbreviation (the CST/IST block) is now dead, no?
please remove it, we shouldn't keep two ways of doing the same thing
There was a problem hiding this comment.
Removed — local abbreviations are already rewritten beforehand.
|
|
||
| /// Extract an optional leading `TZ="..."` rule and return the byte offset | ||
| /// immediately after it along with the effective [`TimeZone`]. | ||
| fn split_leading_tz(input: &str, default_tz: &TimeZone) -> (usize, TimeZone) { |
There was a problem hiding this comment.
this duplicates input_timezone() in date.rs, could we have only one?
also, an unknown zone gives UTC here but the current zone there
There was a problem hiding this comment.
Unified into uucore::time::input_timezone and removed date.rs's copy. Unknown zone names fall back to UTC to match parse_datetime and GNU date.
|
|
||
| /// Return whether `word` is a calendar, weekday, meridiem, ordinal, or relative | ||
| /// keyword in GNU date syntax rather than a timezone abbreviation. | ||
| fn is_date_keyword(word: &str) -> bool { |
There was a problem hiding this comment.
do we really need this list? a keyword will never match the local abbreviation anyway
if it's for perf, comparing the token against the zone abbreviations before probing seems simpler
There was a problem hiding this comment.
Dropped is_date_keyword and replaced it with zone_uses_abbreviation, which checks the zone's current and neighboring transition abbreviations before probing (also avoids probing non-local abbreviations in file_tz_abbreviations).
| .eq_ignore_ascii_case(abbrev) | ||
| }) | ||
| .then_some(offset), | ||
| AmbiguousOffset::Fold { before, after } => [before, after].into_iter().find(|offset| { |
There was a problem hiding this comment.
same closure twice, could be dedup, no?
There was a problem hiding this comment.
Deduplicated into a single matches closure.
| } | ||
|
|
||
| if let Ok(parsed) = parse_datetime::parse_datetime_at_date(ref_zoned, s) | ||
| let rewritten = uucore::time::rewrite_local_tz_abbreviation(s, &ref_zoned, |probe| { |
There was a problem hiding this comment.
same closure as in date.rs, could it live in uucore?
There was a problem hiding this comment.
Moved the parse_datetime call into uucore::time::rewrite_local_tz_abbreviation behind an optional parse-datetime feature, so date and touch call it directly.
| /// `UTC±HH:MM` offset when it matches the effective timezone's abbreviation at | ||
| /// the parsed instant. | ||
| /// | ||
| /// Ambiguous abbreviations such as `CST` (China/Cuba vs US Central) or `IST` |
There was a problem hiding this comment.
please make this doc shorter :)
…ouch Resolve timezone abbreviation tokens against the effective timezone before falling back to parse_datetime's fixed table, regardless of token position (including before the year as in default date output) and consistently across both date and touch. Fixes uutils#16773
b986495 to
e510ab6
Compare
Fixes #16773
Problem
PR #16865 resolved trailing timezone abbreviations in
dateagainst the current timezone, but two paths still fell back toparse_datetime's fixed abbreviation table (whereCSTis-06:00andISTis+05:30):date's own default output places the abbreviation before the year (for exampleSat Jun 1 12:00:00 CST 2024), sodate -dshifted timestamps by +14 hours inAsia/Shanghai/Asia/Taipeiand -4h30m inEurope/Dublin.touch -dpassed inputs directly toparse_datetimewithout checking the current timezone for either trailing or non-trailing abbreviations.Change
uucore::time::rewrite_local_tz_abbreviationto check candidate timezone abbreviation tokens at any position against the effective timezone (including inlineTZ="..."rules and DST fall-back folds) before falling back toparse_datetime's fixed table.j(the local-zone item inparse_datetime) preserves existing rejections of duplicate timezones, conflicting offsets, and epoch timestamps combined with a zone; matching local abbreviations are rewritten to explicitUTC±HH:MMoffsets (orjfor sub-minute historical LMT offsets), while non-local abbreviations remain untouched.dateandtouchto share this helper, and added parameterizedrstestintegration tests covering round-trippingdateoutput throughdate -dandtouch -d, DST folds, inlineTZ="...", non-local fallback preservation, and invalid combinations.