Repository navigation
fix(relative): group month and year adjustments - #360
anastygnome wants to merge 2 commits into
Conversation
e8728e3 to
8921369
Compare
Merging this PR will regress 1 benchmark1 warning
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing |
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
8921369 to
54e0251
Compare
|
@sylvestre can we merge as is? The perf impact is already adressed in the perf pr |
54e0251 to
6a2a923
Compare
| relative: &[relative::Relative], | ||
| ) -> Result<RelativeAdjustment, error::Error> { | ||
| let mut result = RelativeAdjustment::default(); | ||
| for rel in relative { |
There was a problem hiding this comment.
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
| Ok((year, month as u8)) | ||
| } | ||
|
|
||
| fn apply_relative_time(dt: Zoned, relative: RelativeAdjustment) -> Result<Zoned, error::Error> { |
There was a problem hiding this comment.
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
| // 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 { |
There was a problem hiding this comment.
this duplicates the normalization in the TryFrom<Relative> for Span of relative.rs
which now seems unused, could you please remove it?
| /// 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 { |
There was a problem hiding this comment.
the comment here and the one at the call site say the same thing, please keep only one
| "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" |
There was a problem hiding this comment.
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"
|
thanks for this PR! |
|
@sylvestre will address your comments. |
Summary