Skip to content

fix(date): handle timezone format errors gracefully#113

Merged
chaliy merged 1 commit intomainfrom
claude/fix-date-timezone-bug-8s1Zc
Feb 3, 2026
Merged

fix(date): handle timezone format errors gracefully#113
chaliy merged 1 commit intomainfrom
claude/fix-date-timezone-bug-8s1Zc

Conversation

@chaliy
Copy link
Contributor

@chaliy chaliy commented Feb 3, 2026

Summary

  • Fix panic in date builtin when chrono's %Z timezone format fails to determine timezone name
  • Use std::fmt::Write for safe formatting that returns a Result instead of panicking
  • Add comprehensive tests for timezone formatting scenarios

Problem

The date builtin at line 55 used now.format(format).to_string(), which can panic when chrono's Display::fmt returns an error. The default format "%a %b %e %H:%M:%S %Z %Y" includes %Z (timezone name), which can fail in environments where timezone information is unavailable or corrupted.

Solution

Changed from format().to_string() (which panics on fmt error) to write!() which returns a Result, allowing graceful error handling.

Test plan

  • Added test_date_timezone_utc - verifies UTC timezone formatting
  • Added test_date_default_format_includes_timezone - tests default format with %Z
  • Added test_date_timezone_local - tests local timezone with graceful error handling
  • Added test_date_combined_format_with_timezone - tests combined format strings
  • Added test_date_empty_format - tests edge case with empty format
  • Added test_date_literal_text_in_format - tests literal text in format strings
  • All 12 date tests pass
  • cargo clippy passes with no warnings
  • cargo fmt --check passes
  • Full test suite passes with http_client feature

https://claude.ai/code/session_014AiBdrd4m5rkdXRPAVDqta

The date builtin's default format includes %Z (timezone name), which can
fail in chrono when the timezone name cannot be determined. Previously,
format().to_string() would panic when Display::fmt returned an error.

This fix uses write!() to a String instead, which returns a Result,
allowing graceful error handling when formatting fails.

Changes:
- Use std::fmt::Write for safe formatting
- Return ExecResult::err() with descriptive message on format failure
- Add comprehensive tests for timezone formatting

https://claude.ai/code/session_014AiBdrd4m5rkdXRPAVDqta
@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@chaliy chaliy merged commit 270ab94 into main Feb 3, 2026
8 checks passed
@chaliy chaliy deleted the claude/fix-date-timezone-bug-8s1Zc branch February 3, 2026 05:40
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.

2 participants