#relative #date #chrono #calculations

date-calculations

Adjust dates relative to provided Chrono's NaiveDate

2 releases

0.1.1 Dec 20, 2020
0.1.0 Dec 20, 2020

#389 in Date and time

Download history 266/week @ 2024-07-31 249/week @ 2024-08-07 227/week @ 2024-08-14 236/week @ 2024-08-21 190/week @ 2024-08-28 130/week @ 2024-09-04 137/week @ 2024-09-11 235/week @ 2024-09-18 245/week @ 2024-09-25 388/week @ 2024-10-02 219/week @ 2024-10-09 209/week @ 2024-10-16 219/week @ 2024-10-23 176/week @ 2024-10-30 107/week @ 2024-11-06 182/week @ 2024-11-13

723 downloads per month

MIT license

14KB
210 lines

Date Calculations

This is a crate supporting relative date calculations for Chrono's NaiveDate, most notably only Gregorian dates.

Usage

use chrono::prelude::*;
use date_calculations::*;

let twenty_twenty_one = NaiveDate::from_ymd_opt(2021, 1, 31).unwrap();

assert_eq!(next_year(&twenty_twenty_one).unwrap().year(), 2022);
assert_eq!(next_year(&twenty_twenty_one).unwrap().month(), 1);
assert_eq!(next_year(&twenty_twenty_one).unwrap().day(), 1);

assert_eq!(previous_quarter(&twenty_twenty_one).unwrap().year(), 2020);
assert_eq!(previous_quarter(&twenty_twenty_one).unwrap().month(), 10);
assert_eq!(previous_quarter(&twenty_twenty_one).unwrap().day(), 1);

License

Copyright 2020 Josh Clayton. See the LICENSE.

Dependencies

~1MB
~18K SLoC