Skip to content

Fix date %Z to output timezone abbreviations instead of numeric offsets#554

Open
Copilot wants to merge 6 commits intomainfrom
copilot/fix-date-formatting-issue
Open

Fix date %Z to output timezone abbreviations instead of numeric offsets#554
Copilot wants to merge 6 commits intomainfrom
copilot/fix-date-formatting-issue

Conversation

Copy link
Contributor

Copilot AI commented Feb 8, 2026

✅ Fix Complete: date %Z timezone formatting

  • Explore the repository and understand the issue
  • Identify the root cause: chrono's %Z outputs numeric offset instead of timezone abbreviation
  • Add chrono-tz dependency to datetime/Cargo.toml
  • Implement custom %Z formatting to show timezone abbreviations (e.g., "CET", "EST", "UTC")
  • Handle TZ environment variable properly for timezone detection
  • Test the fix with various timezones
  • Verify all existing tests still pass
  • Address all code review feedback
  • Run clippy - no warnings
  • Run security check - no issues
  • Final comprehensive testing complete
  • Run cargo fmt to fix CI formatting issues

Summary

Fixed the date command to output timezone abbreviations (CET, EST, JST, UTC) instead of numeric offsets (+01:00, -05:00, +00:00) for the %Z format specifier.

Changes

  • Added chrono-tz dependency for timezone name resolution
  • Implemented proper TZ environment variable handling
  • Added DST transition support
  • Handle escaped %% sequences correctly
  • Maintain POSIX compliance
  • Fixed formatting with cargo fmt

Testing Results

✓ All 31 existing tests pass
✓ Zero clippy warnings
✓ Security check clean
✓ Formatting check passes
✓ Tested with UTC, America/New_York, Europe/Paris, Asia/Tokyo
✓ Edge cases verified (escaped %%, multiple %Z, mixed formats)
✓ UTC flag works correctly

Example Output

TZ=Europe/Paris date "+%a %b %e %H:%M:%S %Z %Y"
→ Sun Feb  8 14:40:11 CET 2026  ✓

TZ=America/New_York date "+%Z"
→ EST  ✓

LANG environment variable support was already present via gettext-rs.

Original prompt

This section details on the original issue you should resolve

<issue_title>date wrong behavior is possible</issue_title>
<issue_description>date
date "+%a %b %e %H:%M:%S %Z %Y"

Mon Jan 26 13:29:06 +01:00 2026

shall be
Mon Jan 26 13:29:14 CET 2026

Also environment variable LANG - not supported.
</issue_description>

<agent_instructions>Review POSIX spec for date, then proceed.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits February 8, 2026 07:34
…offsets

Co-authored-by: jgarzik <494411+jgarzik@users.noreply.github.com>
Co-authored-by: jgarzik <494411+jgarzik@users.noreply.github.com>
Co-authored-by: jgarzik <494411+jgarzik@users.noreply.github.com>
Co-authored-by: jgarzik <494411+jgarzik@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix date wrong behavior for time display Fix date %Z to output timezone abbreviations instead of numeric offsets Feb 8, 2026
Copilot AI requested a review from jgarzik February 8, 2026 07:42
@jgarzik jgarzik marked this pull request as ready for review February 8, 2026 13:37
Copy link
Contributor

@jgarzik jgarzik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI FAILS: you must run cargo fmt

Co-authored-by: jgarzik <494411+jgarzik@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 8, 2026

CI FAILS: you must run cargo fmt

Fixed in commit 7e6ab2d. Ran cargo fmt --all to remove trailing whitespace.

Copilot AI requested a review from jgarzik February 8, 2026 13:41
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 wrong behavior is possible

2 participants