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.
Fixesuutils/parse_datetime#281.
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.
* 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>
- 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
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.
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.
* 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")
`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
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>
* 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.