I've just released relativedelta 0.4. It brings Python's dateutil.relativedelta to Rust: a RelativeDelta is a value that sets some fields of a date and shifts others, so rules like "the 1st of next month", "the last day of March" or "the last Friday of the month" become data you can build, store, and apply to any date.
use jiff::civil::date; use relativedelta::{RelativeDelta, Weekday}; // The last Friday of the month: go to the 1st, add a month, step back a day, // then move back to a Friday. let last_friday = RelativeDelta::with_day(1) .and_months(1) .and_days(-1) .and_weekday(Weekday::Fri.nth(-1)) .build(); assert_eq!(date(2026, 12, 1) + last_friday, date(2026, 12, 25)); // Months are calendar months: a month after January 31st is the end of February. assert_eq!(date(2026, 1, 31) + RelativeDelta::with_months(1).build(), date(2026, 2, 29)); The same rule works on jiff, time and chrono, each behind a feature (jiff-1, time-03, chrono-04). jiff is recommended for new code; chrono is now unmaintained.
What's new in 0.4:
- A jiff backend, and
time::Datesupport. - Semantics that follow dateutil: absolute fields, calendar-month clamping and weekday jumps give the same results as Python.
checked_*versions of every arithmetic operator, and atry_buildthat reports which field overflowed.- Rules serialize with serde (any format), with an optional JSON schema through
schemars. no_stdwithout an allocator.
Coming from 0.3 or from chronoutil? There are migration guides in the repo's docs/ folder. If you're wondering how this differs from a plain duration or jiff's Span, there's a writeup for that.
Feedback is very welcome, especially if you looked at it and chose something else: what was missing?
1 post - 1 participant

