relativedelta
Rust implementation of relativedelta
known from Python's dateutil library.
Extension to the Duration
from the the time library, which allows for calculating datetimes based on a relative representation of date and time.
Usage
Put this in your Cargo.toml
:
[]
= "0.2"
Optional features:
serde1
: Enable serialization/deserialization via serde.
In the pipeline:
- 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.
- Code coverage setup and badge with travis.com and codecov.io
Examples:
// Construction
let years1 = with_years.new;
let months12 = with_months.new;
assert_eq!;
let years1 = with_years.and_days.new;
// If same parameter is specified twice, only the latest is applied.
let months6 = with_months.with_months.new;
assert_eq!;
// Below is identical to: RelativeDelta::yysmmsdds(Some(2020), 1, Some(1), 3, None, 12).new();
let rddt = with_year.and_years.and_month.and_months.and_days.new;
// Two or more RelativeDeltas can be added and substracted. However, note that constants are lost in the process.
let lhs = yysmmsdds.new;
let rhs = yysmmsdds.new;
assert_eq!;
assert_eq!;
assert_eq!;
// The RelativeDelta can be multiplied with a f64.
assert_eq!;
// This crates party piece is the ability to calculate dates based on already existing chrono::DateTime
// If one would like to get the last day of the month that one is currently in, it could be done with:
println!;
// Above first sets the day of the month to the 1st, then adds a month and subtracts a day.