#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

#366 in Date and time

Download history 129/week @ 2024-07-02 117/week @ 2024-07-09 215/week @ 2024-07-16 235/week @ 2024-07-23 289/week @ 2024-07-30 250/week @ 2024-08-06 222/week @ 2024-08-13 222/week @ 2024-08-20 209/week @ 2024-08-27 138/week @ 2024-09-03 140/week @ 2024-09-10 196/week @ 2024-09-17 240/week @ 2024-09-24 411/week @ 2024-10-01 221/week @ 2024-10-08 186/week @ 2024-10-15

1,103 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