holiday

Crates.ioholiday
lib.rsholiday
version0.1.2
sourcesrc
created_at2021-01-22 05:24:15.849958
updated_at2022-11-26 04:08:34.148477
descriptionA rust library for defining and iterating over annually repeating dates and holidays.
homepagehttps://gitlab.com/ryanobeirne/holiday
repositoryhttps://gitlab.com/ryanobeirne/holiday.git
max_upload_size
id345194
size43,040
Ryan O'Beirne (ryanobeirne)

documentation

https://docs.rs/holiday

README

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.

Commit count: 20

cargo fmt