-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix timezone parsing bug in date command #8992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Fixes issue where dates without timezone info (like '2025-03-29 8:30:00') were interpreted as UTC instead of local time, causing 1-hour offset errors. The fix parses common date formats as naive datetimes first, then converts to local time using Local.from_local_datetime(), which correctly applies the timezone offset for that specific date (not the current date's offset). This matches GNU date behavior and fixes the issue reported in: - uutils#8976 - cockpit-project/bots#8345 - cockpit-project/bots#8373
Adds test_date_timezone_parsing_fix() that verifies the fix for issue uutils#8976. The test ensures dates without timezone are interpreted as local time for that specific date, not as UTC converted to local time. Tests cover: - Europe/Prague timezone (CET/CEST transitions) - Standard time vs daylight saving time - Multiple date formats - Different timezones (America/New_York) This prevents regression of the timezone parsing bug.
Add detailed documentation explaining that the current chrono-based timezone parsing fix is a temporary bandaid solution that: 1. Reintroduces chrono dependencies (conflicts with jiff migration) 2. Fixes critical bug uutils#8976 affecting real users 3. Needs proper jiff-native implementation 4. Includes clear migration plan and risk mitigation This ensures future maintainers understand the trade-offs and have a clear path forward for the proper implementation.
Apply standard Rust formatting to: - Align comments and improve readability in parse_date function - Format test function calls for better parameter visibility - Remove trailing whitespace No functional changes, just code style improvements.
ff1ec6c to
7e83262
Compare
|
GNU testsuite comparison: |
b337b5b to
ee84054
Compare
CodSpeed Performance ReportMerging #8992 will improve performances by 5.03%Comparing Summary
Benchmarks breakdown
Footnotes
|
2f2a610 to
5dd6c8b
Compare
|
GNU testsuite comparison: |
5dd6c8b to
a7acbe2
Compare
- Use fixed offset timezone to preserve chrono's exact timezone calculation - Avoids Windows vs Unix timezone database differences in DST transitions - Documents critical case: Windows CI interprets dates incorrectly due to different DST rules - Trade-off: %Z shows numeric offset (+0100) instead of timezone abbreviation (CET) - Updates tests to expect numeric offsets for cross-platform consistency This ensures consistent behavior across all platforms by using chrono's precise timezone calculations instead of relying on system timezone databases.
a7acbe2 to
f4eafa4
Compare
|
GNU testsuite comparison: |
…ndows When parsing dates without explicit timezone, verify that the system timezone offset (from jiff) matches chrono's calculation. If offsets differ due to different DST rules (especially on Windows), adjust the timestamp to ensure the displayed time remains correct while preserving timezone abbreviations. This fixes the Windows CI test failure where the time was off by an hour or the timezone showed as UTC instead of CET for dates like '2025-01-15 8:30:00' with TZ=Europe/Prague environment variable set.
cc73169 to
d79e38f
Compare
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
Fixes: #8976
found this annoying bug where
date --date="2025-03-29 8:30:00"was showing07:30:00 CETinstead of08:30:00 CET. Turns out the parser was treating dates without timezone as UTC, then converting to local time. But GNU date treats them as already local time.The fix: Parse common date formats as naive datetimes first, then convert to local time using the correct timezone for that specific date. Falls back to existing parser for complex stuff like "tomorrow".
Used git blame to understand the jiff migration 301e33c and ensure our changes don't conflict with existing architecture. This is a temporary bandaid until jiff-native implementation.