timext 0.1.1

The collection of time-rs/time extensions for calendar arithmetics, incomplete formats handling, imprecise time, and other things time crate is not intended for.
Documentation
timext-0.1.1 has been yanked.

xwde: timext

Build Status Crate Docs Crate Version

Warning : The library is in active development. Expect breaking changes.

The collection of time-rs/time extensions for calendar arithmetics, incomplete formats handling, imprecise time, and other things time crate is not intended for.

  • Introduces timext:CalendarDuration and extends time::Date, time::PrimitiveDateTime, and time::OffsetDateTime with several methods to enable arithmetic operations related to months and years. Additionally, attaches conversion methods to i64 and f64 to improve ease of use.
use time::{Date, Month};
use timext::ext::NumericCalendarDuration;

fn main() {
    let d0 = Date::from_calendar_date(2023, Month::January, 31).unwrap();
    let d1 = Date::from_calendar_date(2023, Month::February, 28).unwrap();
    assert_eq!(d0 + 1.months(), d1);

    let d0 = Date::from_calendar_date(2024, Month::February, 29).unwrap();
    let d1 = Date::from_calendar_date(2025, Month::February, 28).unwrap();
    assert_eq!(d0 + 1.years(), d1);
}

Links