date: fix %+ and %_ modifier edge cases#10999
Conversation
Fixes uutils#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")
c00657a to
1db79d3
Compare
|
GNU testsuite comparison: |
| let explicit_width = !width_str.is_empty(); | ||
| let modified = apply_modifiers(&formatted, flags, width, spec, explicit_width); |
There was a problem hiding this comment.
Why do you introduce explicit_width? If I look at the tests, there seems to be a connection between width and explicit_width: if width is 0, explicit_width is false. And if width is greater than 0, explicit_width is always true. And thus it seems unnecessary to pass explicit_width to apply_modifiers. Maybe I'm missing something?
There was a problem hiding this comment.
tks, i found it.
| Format | GNU | UU | Gap |
|---|---|---|---|
| %0e (day=5) | 05 | 5 | UU ignores 0 flag on %e |
| %0k (hour=5) | 05 | 5 | UU ignores 0 flag on %k |
%([_0^#+-]*)(\d*)(:*[a-zA-Z]) always consumes 0 as a flag (group 1), never as width digits (group 2) that never "0"
- Add is_space_padded_specifier() to recognize %e, %k, %l as space-padded - Fix %C default width from 4 to 2 (century is 00-99) - Fix effective_width logic to apply default width when padding flag changes the default padding character - Add strip logic for space→zero padding conversion
|
GNU testsuite comparison: |
|
Please also add integration tests in test_date.rs |
|
GNU testsuite comparison: |
|
please merge the tests into a single tests with a loop with input/expected as a datastrucutre |
6d02dc1 to
18a1300
Compare
|
GNU testsuite comparison: |
Add consolidated integration test for format modifier behavior without explicit width, covering the new features in format_modifiers.rs: - is_space_padded_specifier(): Tests %e, %k, %l default space padding and %0e, %0k, %0l zero-padding override - get_default_width(): Tests %_d, %_m, %_H, %_Y, %_C, %_j using default widths - explicit_width parameter: Tests %+Y with/without explicit width Uses a data-driven test structure with all cases in a single vector.
|
please run pre-commit install |
|
sr, the precommit causes issues with SELinux, but since am using macOS, I always run with |
18a1300 to
d3cae2a
Compare
|
GNU testsuite comparison: |
Fixes #10957
%+ without width now omits sign for 4-digit years; %_ now pads to default width. Adds get_default_width() and explicit_width parameter