#date-time #date #time #annual #anniversary

holiday

A rust library for defining and iterating over annually repeating dates and holidays

3 releases

0.1.2 Nov 26, 2022
0.1.1 Jan 22, 2021
0.1.0 Jan 22, 2021

#261 in Date and time

Download history 30/week @ 2024-07-19 65/week @ 2024-07-26 30/week @ 2024-08-02 5/week @ 2024-08-09 2/week @ 2024-08-16 25/week @ 2024-08-23 8/week @ 2024-08-30 19/week @ 2024-09-06 5/week @ 2024-09-13 39/week @ 2024-09-20 34/week @ 2024-09-27 12/week @ 2024-10-04 5/week @ 2024-10-11 6/week @ 2024-10-18 50/week @ 2024-10-25 40/week @ 2024-11-01

102 downloads per month
Used in rustc-holidays

MIT license

36KB
868 lines

holiday

A rust library for defining and iterating over annually repeating dates and holidays.

Create a new Holiday

A Holiday can be either a fixed date like 'April 2nd' or an nth weekday of a month, like '1st Friday in April'.

use holiday::*;
use chrono::{Weekday, NaiveDate};

// Regular `fixed` holiday
let holiday = Holiday::new_fixed("April 2nd", April, 2);
assert_eq!(holiday.in_year(2021), NaiveDate::from_ymd(2021, 4, 2));
assert_eq!(holiday, NaiveDate::from_ymd(2021, 4, 2));
assert_eq!(holiday, NaiveDate::from_ymd(2022, 4, 2));

// Pastover: First Friday in April, an `nth` holiday
let pastover = Holiday::new_nth("Pastover", First, Weekday::Fri, April);
assert_eq!(pastover.in_year(2021), NaiveDate::from_ymd(2021, 4, 2));
assert_eq!(pastover, NaiveDate::from_ymd(2021, 4, 2));
assert_eq!(pastover, NaiveDate::from_ymd(2022, 4, 1));

Iterate over the occurrences of a Holiday.

The HolidayIter type is an iterator over the occurrences of a Holiday.


lib.rs:

holiday

A library for defining annually repeating dates and holidays

Create a new Holiday

A Holiday can be either a fixed date like 'April 2nd' or an nth weekday of a month, like '1st Friday in April'.

use holiday::*;
use chrono::{Weekday, NaiveDate};

// Regular `fixed` holiday
let holiday = Holiday::new_fixed("April 2nd", April, 2);
assert_eq!(holiday.in_year(2021), NaiveDate::from_ymd(2021, 4, 2));
assert_eq!(holiday, NaiveDate::from_ymd(2021, 4, 2));
assert_eq!(holiday, NaiveDate::from_ymd(2022, 4, 2));

// Pastover: First Friday in April, an `nth` holiday
let pastover = Holiday::new_nth("Pastover", First, Weekday::Fri, April);
assert_eq!(pastover.in_year(2021), NaiveDate::from_ymd(2021, 4, 2));
assert_eq!(pastover, NaiveDate::from_ymd(2021, 4, 2));
assert_eq!(pastover, NaiveDate::from_ymd(2022, 4, 1));

Dependencies

~1MB
~18K SLoC