relativedelta-0.1.0 has been yanked.
relativedelta
Extention to the Duration from the the time library, allowing calculating datetimes based on a relative representation of datetime.
Usage
If you cannot wait until proper crate/first release, put this in your Cargo.toml:
[]
= { = "https://github.com/timkaas/relativedelta"}
Optional features:
serde: Enable serialization/deserialization via serde.
In the works:
- Hook up to travis.com.
- Mitigation of month rounding error when init with floats or mul with floats.
- Create a proper crate and publish on crates.io.
- Documentation and doctest.
Examples:
use relativedelta;
let year = 2020;
let month = 4;
let month2 = 3;
let months = -11;
let day = 28;
let days = 31;
let hour = 12;
let min = 35;
let sec = 48;
let n_secs = -11_111_111_111;
let dt = Utc.ymd.and_hms;
let ddt = years
.with_month
.with_months
.with_days
.with_nanoseconds
.new;
let add_1_year = years.new;
assert_eq!;
let sub_1_year = years.new;
assert_eq!;
let set_year = year.new;
assert_eq!;
let set_year = year.new;
assert_eq!;
let add_69_months = months.new;
// Expected after fix
assert_eq!;
assert_eq!;
assert_eq!;
let sub_6_months = months.new;
assert_eq!;
let sub_47_months = months.new;
// Expected after fix
assert_eq!;
assert_eq!;
assert_eq!;
let add_400_days = days.new;
assert_eq!;
let sub_400_days = days.new;
assert_eq!;
let pay1 = day.with_days.with_month.with_months.new;
assert_eq!;
let pay2 = day.with_days.with_month.with_months.new;
assert_eq!;
let pay3 = day.with_days.with_month.with_months.new;
assert_eq!;
let pay4 = day.with_days.with_month.with_months.new;
assert_eq!;
// Multiplication
let ddt = years.and_months.and_days.and_hours.new;
let r = ddt * 0.42_f64;
println!;
// Init with floats
let ddt = ysmsdshsmsssns_f.new;
println!;
let ddt = ysmsdshsmsssns_f.new;
assert_eq!;