* 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.
fixed gnu rfc822-1
RFC-822/RFC-2822/RFC-5322 formats must use English day and month names
regardless of locale per RFC specification. Previously, these formats
were being localized (e.g., "So" instead of "Sun" with de_DE locale).