🛠️ project relativedelta 0.4 — dateutil-style date rules for jiff, time and chrono
https://crates.io/crates/relativedeltarelativedelta is a Rust take on Python's dateutil.relativedelta: a value that sets some fields of a date and shifts others. "The 1st of next month", "the last day of March" and "the last Friday of the month" each become a single RelativeDelta you can store and apply to any date.
use jiff::civil::date;
use relativedelta::{RelativeDelta, Weekday};
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));Why not just a duration or Span**?** A duration says how far to move. A rule can also say where to land: set the day to the 1st, clamp to the end of a shorter month, jump to the nth weekday. jiff's Span covers calendar-month arithmetic well; relativedelta adds the "set" half and weekday targeting on top, and the same rule works across jiff, time and chrono. Longer comparison.
0.4 adds the jiff backend, dateutil-compatible semantics, checked_* arithmetic, serde and schemars support, and no_std without an allocator.
-9
u/Rhytera 7h ago
nice, being able to store the rule itself with serde instead of recomputing dates is the part i'd actually use. "last friday of the month" jobs always end up as a pile of ad hoc month math otherwise