Crates.io | calendar_calculator |
lib.rs | calendar_calculator |
version | 0.3.0 |
source | src |
created_at | 2023-01-13 22:49:03.404188 |
updated_at | 2023-01-14 10:31:45.677542 |
description | The calendar_calculator crate is a simple library crate that provides a range of functionalities for calculating distances between two dates expressed in str slice format, as well as adding different durations to a given date. With this crate, users can easily and quickly perform calculations related to dates and distances. |
homepage | |
repository | https://github.com/emanuele-em/calendar_calculator |
max_upload_size | |
id | 758201 |
size | 13,528 |
The calendar_calculator crate is a simple library crate that provides a range of functionalities for calculating distances between two dates expressed in str slice format, as well as adding different durations to a given date. With this crate, users can easily and quickly perform calculations related to dates and distances.
This crate works with Cargo. Add the following to your Cargo.toml dependencies section:
[dependencies]
calendar_calculator = "0.2.0"
or simply run
cargo add calendar_calculator
use calendar_calculator::CalendarCalculator
let n = 10;
let date = ("2023-01-12 00:00:00").parse().unwrap();
// return StrToDate{2001, 02, 18, 10, 00, 10}
let (y, m, d, hh, mm, ss) = date.add_seconds(n);
// return StrToDate{2001, 02, 18, 10, 10, 00}
let (y, m, d, hh, mm, ss) = date.add_minutes(n);
// return StrToDate{2001, 02, 18, 20, 10, 00}
let (y, m, d, hh, mm, ss) = date.add_hours(n);
// return StrToDate{2001, 02, 28, 10, 00, 00}
let (y, m, d, hh, mm, ss) = date.add_days(n);
// return StrToDate{2001, 04, 29, 10, 00, 00}
let (y, m, d, hh, mm, ss) = date.add_weeks(n);
// return StrToDate{2001, 12, 18, 10, 00, 00}
let (y, m, d, hh, mm, ss) = date.add_months(n);
// return StrToDate{2011, 02, 18, 10, 00, 00}
let (y, m, d, hh, mm, ss) = date.add_years(n);
// return (2011, 02, 18, 10, 00, 00)
let (y, m, d, hh, mm, ss) = date.add_years(n);
// return Distance
// {
// seconds: 113788800,
// minutes: 1896480,
// hours: 31608,
// days: 1317,
// weeks: 188,
// months: 43,
// years: 3,
// sundays: 189,
// saturdays: 189,
// working_days: 1128,
// }
println!({},("1997-07-12 10:00:00").parse().unwrap().distance_between(date));
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.