Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(format date): resolve %r when the locale's am/pm fallback also carries %O - #18924

Merged
fdncred merged 1 commit into
nushell:mainfrom
aron-intframe:fix/format-date-empty-ampm-alt-modifier
Aug 28, 2026
Merged

fix(format date): resolve %r when the locale's am/pm fallback also carries %O#18924
fdncred merged 1 commit into
nushell:mainfrom
aron-intframe:fix/format-date-empty-ampm-alt-modifier

Conversation

@aron-intframe

@aron-intframe aron-intframe commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Description

Follow-up to #18918. az_IR and fa_IR have an empty t_fmt_ampm, so #18918 leaves %r to chrono, the carve-out that keeps de_DE from rendering blank. But chrono's fallback for an empty am/pm form is the locale's t_fmt, and for those two that is %OH:%OM:%OS, so the modifier walks back in and %r still errors.

The fix makes chrono's own fallback explicit: when t_fmt_ampm is empty, substitute t_fmt ourselves so it goes through the stripping path. de_DE, fr_FR and nl_NL are byte-identical, their t_fmt is %T.

#18918 also named the wrong set of affected locales. Scanning every LC_TIME block in pure-rust-locales 0.8.2 it is nine, not two: az_IR, fa_IR, lo_LA, lzh_TW, mnw_MM, my_MM, or_IN, shn_MM, th_TH. Stripping already covered seven of them; a test now pins all nine so a locale table bump cannot quietly break one.

Mutation-checked: dropping the fallback turns three tests red with TypeMismatch { err_message: "invalid format" }. Green, cargo test -p nu-command --lib 814 passed and --test tests 2930 passed, fmt and clippy clean. Linux, Rust stable, nu-command only.

User-facing changes (Release notes)

format date %r now works under the last two locales that still failed

#18918 fixed format date under locales whose formats use %E/%O, but az_IR and fa_IR still failed on %r, because they define no am/pm format and their plain time format carries the modifier again:

# with LC_TIME=fa_IR.UTF-8
date now | format date %r
# before: Error: nu::shell::type_mismatch, invalid format
# after:  20:00:12

Every other locale, including de_DE, fr_FR and nl_NL, renders exactly as before.

Additional notes

Follow-up to #18918, which fixed #15266. Upstream fix: chronotope/chrono#1816.

…rries %O

Follow-up to nushell#18918. Two of the affected locales still failed.

`az_IR` and `fa_IR` have an empty `t_fmt_ampm`, so nushell#18918 left `%r`
alone for chrono to resolve, the way `de_DE`/`fr_FR`/`nl_NL` need. But
chrono's fallback for an empty am/pm form is the locale's `t_fmt`, and
for these two that is `%OH:%OM:%OS` — the modifier comes straight back
in, and `format date %r` stays `nu::shell::type_mismatch, invalid
format`.

Substituting `t_fmt` ourselves when `t_fmt_ampm` is empty makes the same
fallback chrono makes, but through the stripping path. `de_DE`, `fr_FR`
and `nl_NL` are byte-identical (their `t_fmt` is `%T`).

While checking this, the full set of locales carrying `%E`/`%O` in
`LC_TIME` turned out to be nine, not the two named in nushell#18918: `az_IR`,
`fa_IR`, `lo_LA`, `lzh_TW`, `mnw_MM`, `my_MM`, `or_IN`, `shn_MM`,
`th_TH`. A test now renders `%x`, `%X`, `%c` and `%r` under all nine.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@fdncred fdncred added notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes labels Aug 28, 2026
@fdncred

fdncred commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Next PR, tell your llm to be less verbose. Thanks

@fdncred
fdncred merged commit d6a9f6b into nushell:main Aug 28, 2026
15 checks passed
@github-actions github-actions Bot added this to the v0.116.0 milestone Aug 28, 2026
@fdncred

fdncred commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

I'd love to switch away from chrono to jiff

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

Labels

notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug Report: Type Mismatch Error in default_env.nu When Using format date '%x %X'

3 participants