Skip to content

fix(date): support %s, %F, %T and other GNU format specifiers - #214

Merged
ferdingler merged 2 commits into
strands-agents:mainfrom
ferdingler:fix/date-format-specifiers
Nov 12, 2026
Merged

ferdingler merged 2 commits into
strands-agents:mainfrom
ferdingler:fix/date-format-specifiers

Conversation

@ferdingler

@ferdingler ferdingler commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Description

date +FORMAT only knew a handful of specifiers and expanded them one at a time, so anything else came out wrong without any error. date +%s, which people use all the time for timing, printed a literal %s. And because expanded text got re-scanned, %%Y turned into the year instead of %Y:

$ date +%s
%s
$ date +%%Y
%2026

Now the format string is expanded in a single pass and covers the common GNU specifiers (%s, %F, %T, %N, %j, %A, %B, %z, %Z, %% and friends). Unknown ones are printed as-is, like GNU does. date, date -u and the specifiers that worked before give the same output as before.

I compared the output against GNU date in UTC for fixed timestamps, including edge cases like midnight, Sundays and day 366 of a leap year. I left out GNU's padding flags like %-d and -d parsing, those can come separately.

Related Issues

Part of #207

Documentation PR

N/A

Type of Change

Bug fix

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce new warnings.

  • I ran the relevant test suites for the bindings I touched (cargo test --workspace --all-targets, pytest tests/python, npm test)
  • If I touched Rust, I ran cargo fmt and cargo clippy

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ferdingler
ferdingler marked this pull request as ready for review November 12, 2026 04:56
@ferdingler
ferdingler requested a review from a team as a code owner November 12, 2026 04:56
@ferdingler

Copy link
Copy Markdown
Collaborator Author

@strandly-the-agent please review

@strandly-the-agent strandly-the-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approve. I found no blocking issues. Every specifier you added matches GNU date byte for byte (TZ=UTC LC_ALL=C) across 223 timestamps, including the AM/PM boundaries, leap days, day 366, and 2100 (not a leap year). %%Y no longer gets expanded a second time, and plain date prints the same as before.

Non-blocking question: should %:z be added in this PR? Agents often write ISO-8601 timestamps as date '+%FT%T%:z', and that currently prints 2025-11-06T11:34:56%:z. A few other specifiers GNU supports also still print literally: %k %l %P %h %C %r %x %X %q %G %V %U. Most of them would be one more line in the match at src/commands/date.rs:177. Leaving them for a follow-up under #207 is fine too.

✅ What I verified
  • Head 29966af. cargo test --lib date: 6 passed. cargo test --test shell_integration date: 8 passed. cargo fmt --check is clean, and clippy reports no warnings in date.rs.
  • Compared format_date with GNU coreutils 9.1 on 223 timestamps for every specifier listed in the help text, plus %%Y and %%%Y: 0 mismatches.
  • I also ran the built strands-shell -c binary next to host date. Every specifier the PR claims matched at the same second.
  • The new tests check real behaviour. On base, date_epoch_seconds would get a literal %s, and date_percent_escape would get %2025 100%%.
  • The help text lists exactly what was added. The README and bindings don't document date.
Appendix: non-blocking (1)
  • ⚪ This predates the PR: %c includes UTC (date.rs:183-186), while GNU +%c in the C locale prints Thu Nov 6 11:34:56 2025. Plain date relies on this format and matches GNU, so changing it would need a separate default-format path. I didn't file an issue for it because it's minor.

@ferdingler
ferdingler merged commit e17d715 into strands-agents:main Nov 12, 2026
30 of 59 checks passed
@ferdingler
ferdingler deleted the fix/date-format-specifiers branch November 12, 2026 17:16
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