Skip to content

Conversation

@naoNao89
Copy link
Contributor

@naoNao89 naoNao89 commented Oct 24, 2025

Fixes: #8976
found this annoying bug where date --date="2025-03-29 8:30:00" was showing 07:30:00 CET instead of 08: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.

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.
@naoNao89 naoNao89 force-pushed the fix-date-timezone-parsing branch from ff1ec6c to 7e83262 Compare October 24, 2025 12:51
@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch)

@naoNao89 naoNao89 force-pushed the fix-date-timezone-parsing branch 2 times, most recently from b337b5b to ee84054 Compare October 24, 2025 13:29
@codspeed-hq
Copy link

codspeed-hq bot commented Oct 24, 2025

CodSpeed Performance Report

Merging #8992 will improve performances by 5.03%

Comparing naoNao89:fix-date-timezone-parsing (7cdfee5) with main (21ee64c)

Summary

⚡ 1 improvement
✅ 105 untouched
⏩ 73 skipped1

Benchmarks breakdown

Benchmark BASE HEAD Change
sort_random_strings 31.8 ms 30.3 ms +5.03%

Footnotes

  1. 73 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@naoNao89 naoNao89 force-pushed the fix-date-timezone-parsing branch 4 times, most recently from 2f2a610 to 5dd6c8b Compare October 24, 2025 13:54
@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)

@naoNao89 naoNao89 force-pushed the fix-date-timezone-parsing branch from 5dd6c8b to a7acbe2 Compare October 24, 2025 14:18
- 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.
@naoNao89 naoNao89 force-pushed the fix-date-timezone-parsing branch from a7acbe2 to f4eafa4 Compare October 24, 2025 14:21
@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch)

…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.
@naoNao89 naoNao89 force-pushed the fix-date-timezone-parsing branch from cc73169 to d79e38f Compare October 24, 2025 14:55
@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch)

@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/misc/tee (fails in this run but passes in the 'main' branch)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

date: --date returns wrong time, off by 1 hour

1 participant