Skip to content

fix(relative): group month and year adjustments - #360

Open
anastygnome wants to merge 2 commits into
uutils:mainfrom
anastygnome:split/month-year-grouping
Open

anastygnome wants to merge 2 commits into
uutils:mainfrom
anastygnome:split/month-year-grouping

Conversation

@anastygnome

@anastygnome anastygnome commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Accumulate relative year/month/day/time fields before applying them.
  • Normalize grouped year/month changes with GNU-compatible overflow behavior.
  • Add chained month/year regression coverage

@anastygnome
anastygnome force-pushed the split/month-year-grouping branch from e8728e3 to 8921369 Compare November 12, 2026 11:57
@codspeed

codspeed Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will regress 1 benchmark

1 warning

⚠️ 15 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚡ 1 improved benchmark
❌ 1 regressed benchmark
✅ 19 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ parse_relative_time_complex 61.6 µs 64.6 µs -4.56%
⚡ parse_now 30.1 µs 28 µs +7.47%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing anastygnome:split/month-year-grouping (6a2a923) with main (027bcd3)

Open in CodSpeed

@codecov

codecov Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.70%. Comparing base (027bcd3) to head (6a2a923).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #360      +/-   ##
==========================================
- Coverage   98.97%   98.70%   -0.28%     
==========================================
  Files          21       21              
  Lines        4696     4784      +88     
  Branches      143      149       +6     
==========================================
+ Hits         4648     4722      +74     
- Misses         47       61      +14     
  Partials        1        1              
Flag Coverage Δ
macos_latest 98.70% <100.00%> (-0.28%) ⬇️
ubuntu_latest 98.70% <100.00%> (-0.28%) ⬇️
windows_latest 12.66% <30.61%> (+0.27%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@anastygnome
anastygnome force-pushed the split/month-year-grouping branch from 8921369 to 54e0251 Compare November 15, 2026 12:29
@anastygnome

Copy link
Copy Markdown
Contributor Author

@sylvestre can we merge as is? The perf impact is already adressed in the perf pr

@anastygnome
anastygnome force-pushed the split/month-year-grouping branch from 54e0251 to 6a2a923 Compare November 16, 2026 11:04
Comment thread src/items/builder.rs
relative: &[relative::Relative],
) -> Result<RelativeAdjustment, error::Error> {
let mut result = RelativeAdjustment::default();
for rel in relative {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

almost the same checked_add block 6 times, could be dedup, no?
a small helper or closure taking the field and the error string would do

Comment thread src/items/builder.rs
Ok((year, month as u8))
}

fn apply_relative_time(dt: Zoned, relative: RelativeAdjustment) -> Result<Zoned, error::Error> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we use jiff::SignedDuration here?
SignedDuration::new(secs, nanos) already normalizes mixed signs, so most of this function and the manual sign fix would go away

Comment thread src/items/builder.rs
// Relative::Seconds stores negative fractional values in timestamp form,
// e.g. (-1, 500_000_000) for -0.5 seconds. Jiff spans require the seconds
// and nanoseconds components to have the same sign, so normalize them.
let (seconds, nanoseconds) = if seconds < 0 && nanoseconds > 0 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this duplicates the normalization in the TryFrom<Relative> for Span of relative.rs
which now seems unused, could you please remove it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will check

Comment thread src/items/builder.rs
/// applies all year/month changes together, followed by days and then the
/// clock units, rather than applying the input items one at a time.
#[derive(Clone, Copy, Debug, Default)]
struct RelativeAdjustment {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the comment here and the one at the call site say the same thing, please keep only one

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Comment thread tests/date.rs
"2020-02-29 00:00:00",
"1 year ago 1 month",
"2019-04-01 00:00:00+00:00"
"2019-03-29 00:00:00+00:00"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a test with the same unit twice, e.g. "1 month 1 month" from 2024-01-31
and one with the time unit before the date one, e.g. "4 hours 1 month"

@sylvestre

Copy link
Copy Markdown
Contributor

thanks for this PR!
The approach looks right, but the new code repeats itself (inline comments). CodSpeed also reports 2 regressed benchmarks, could you please check them?

@anastygnome

Copy link
Copy Markdown
Contributor Author

@sylvestre will address your comments.
The codspeed will be handled in the perf pr if that's ok.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants