Commit Graph
128 Commits
Author SHA1 Message Date
0xSoftBoiandGitHub dfd62976de date: re-zone trailing TZ abbreviation input to local timezone (#12327)
The dedicated abbreviation-aware path `try_parse_with_abbreviation` in
`src/uu/date/src/date.rs` returned a `Zoned` in the input abbreviation
timezone (e.g. `-05` for `EST`). The generic `parse_datetime` fallback
already re-zones to `now.time_zone()` for display, so identical inputs
took two divergent code paths and only one matched GNU `date`.

GNU treats a trailing TZ abbreviation as describing the *input*
timezone; the output is always re-zoned into the local zone (or UTC
under `-u`). For example, under `TZ=UTC`:

    $ date -d "2024-01-01 EST"        # GNU
    Mon Jan  1 05:00:00 UTC 2024

uutils previously emitted `Mon Jan  1 00:00:00 -05 2024`.

Convert the parsed instant to `now.time_zone()` before returning,
matching the fallback path and GNU’s behavior. `-u` still works
because `now` is already zoned to UTC in that case (date.rs:362),
and the final output stage still applies `with_time_zone(TimeZone::UTC)`
when `settings.utc` is set.

Un-ignores the existing regression test for this issue.

Fixes uutils/parse_datetime#281.
2026-05-16 22:01:37 +02:00
Sylvestre LedruandDaniel Hofstetter f057cc6a01 tests: replace .no_stdout().no_stderr() chains with .no_output()
Bulk rename of the antipattern across 19 test files (136 occurrences).
.no_output() is the established shorthand in the uutests framework
for asserting both empty stdout and empty stderr.
2026-05-12 09:31:31 +02:00
oech3andDaniel Hofstetter 529467d8e5 reduce usage of nix::unistd::geteuid 2026-05-06 11:41:38 +02:00
Devel08GitHubpre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
5fa0aba94d date: don't ignore width prefix in %N format specifier (#12010)
* do not ignore %N if specified width is smaller than default width

* add test for issue #12001

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* cargo clippy

* truncate instead of popping in a loop

* Update format_modifiers.rs

* skip truncation if width is 0

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2026-04-27 14:59:09 +02:00
oech3andDaniel Hofstetter 9978ac67f2 date: use cfg unix 2026-04-23 09:02:29 +02:00
Sylvestre LedruandDaniel Hofstetter c4093734e2 ci: install hu_HU.UTF-8 (and peers) for l10n cargo test job 2026-04-06 15:10:31 +02:00
MegaBrutalandDaniel Hofstetter 0a5c60f5cf Tests for Hungarian locale 2026-04-06 15:10:31 +02:00
vishakha1411andDaniel Hofstetter 51094702d2 date: honor narrow width on wide default strftime fields 2026-04-06 10:16:00 +02:00
vishakha1411andDaniel Hofstetter b41d591cde date: fix %#P case-swap on lowercase am/pm 2026-04-06 09:48:18 +02:00
Sylvestre Ledru 88fb82a4a7 date: add ignored tests for GNU compatibility gaps found by fuzz_date 2026-04-05 23:49:37 +02:00
Sylvestre Ledru 9ebeacb84d Modify spell-checker ignore comments
Updated spell-checker ignore list in test_date.rs
2026-04-05 10:13:31 +02:00
Sylvestre Ledru dbdd2ddfda date: extract try_alloc_padded helper and add large-width test
Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
2026-04-05 10:13:31 +02:00
mattsuandSylvestre Ledru c81e9d00b9 fix: improve error handling for format modifier width parsing
- Changed FormatError::FieldWidthTooLarge to store width as String instead of usize
- Updated error message generation to use FluentArgs for proper localization
- Fixed width parsing to return FormatError instead of panicking on parse failure
- Updated error message formatting to use get_message_with_args for consistency
- Fixed test assertions to compare width as String instead of usize
2026-04-05 10:13:31 +02:00
mattsuandSylvestre Ledru 12b30cbca1 fix(date): add error handling for format modifier width overflow
Added proper error handling for format modifier width calculations that could overflow or fail allocation. The change replaces generic error messages with a specific error type `FieldWidthTooLarge` that includes the problematic width and specifier values, improving error reporting for date format operations.
2026-04-05 10:13:31 +02:00
mattsuandSylvestre Ledru 136b1841b3 fix(date): handle width overflow in format modifiers
Update `apply_modifiers` to return `Result<String, FormatError>` and check for integer overflow when calculating padding length. This prevents potential panics or incorrect formatting when very large width values are specified. The change adds proper error handling for the "field width too large" case and propagates errors through the formatting pipeline.
2026-04-05 10:13:31 +02:00
Sylvestre LedruandDaniel Hofstetter ffa088d467 tests: deduplicate locale availability checks into shared is_locale_available() 2026-04-01 14:36:58 +02:00
xtqqczzeandGitHub f00a050106 clippy: fix nightly lints (#11232) 2026-03-08 09:13:23 +01:00
cerdelenandDaniel Hofstetter a6b0276966 date: extend tz abbreviation lookup 2026-03-07 16:46:48 +01:00
Cả thế giới là RustandGitHub 2c3eab9440 date: fix %+ and %_ modifier edge cases (#10999)
* date: fix %+ and %_ modifier edge cases

Fixes #10957:

1. %+ without explicit width now correctly omits sign for years
   with <= 4 digits. Sign is only added when explicit width is
   provided or year exceeds default width.

2. %_ without explicit width now correctly pads to the specifier's
   default width (e.g., %_m produces " 6" instead of "6").

Changes:
- Add get_default_width() function mapping specifiers to POSIX
  default widths
- Modify apply_modifiers() to accept explicit_width parameter
- Update tests for new behavior

Test results:
- date -d '1999-06-01' '+%+Y' -> "1999" (was "+1999")
- date -d '1999-06-01' '+%_m' -> " 6" (was "6")
2026-02-27 09:13:59 +01:00
Alvaro GuimaraesandDaniel Hofstetter e4cc92ba46 date: fix timezone abbreviations using wrong offset outside their DST season 2026-02-21 16:28:56 +01:00
yachiandDaniel Hofstetter 8c98b152c6 date: fix -d with relative dates and timezone abbreviations
`try_parse_with_abbreviation` resolved relative dates like "yesterday"
against the system clock instead of the caller-provided reference time.
Pass `now` through so both code paths use the same reference.

Fixes #10788
2026-02-19 11:00:55 +01:00
b4395348c8 date: Fix Error message missing '+' for format string after valid d flag (#10982)
* date: Fix Errors message missing '+' for format string after valid d flag

* Update src/uu/date/locales/fr-FR.ftl

Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>

---------

Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
2026-02-17 09:28:58 +01:00
Sylvestre LedruandGitHub a7f55cbedc date: fix subfmt-up1, fill-1, pct-pct, and invalid-high-bit-set tests (#10940) 2026-02-15 09:14:29 -08:00
72c782fbfd date: fix double periods in Hungarian month abbreviations (#10945)
ICU's DateTimeFormatter with fieldsets::M::medium() returns month
abbreviations with trailing periods (e.g., "febr." for Hungarian).
When the Hungarian locale format string contains "%Y. %b. %d"
(with periods after year and month), the ICU output resulted in
double periods: "febr.."

This fix strips trailing periods from ICU month abbreviations to
match the standard C/POSIX locale behavior.

Also adds a new test case for abbreviated month names across
multiple locales to prevent regression.

Fixes #10921

Co-authored-by: naoNao89 <naoNao89@users.noreply.github.com>
2026-02-15 13:15:29 +01:00
Sylvestre LedruandGitHub 6d9af5ae77 date: add tests to match GNU's (#10939)
* date: add test for rel-2b GNU test

Test correct month arithmetic maintaining same day of month, and
month overflow when day doesn't exist in target month.

* date: add test for cross-TZ-mishandled GNU test

Test parsing dates with embedded timezone specifications.
2026-02-14 13:55:16 -08:00