Crate holiday

source ·
Expand description

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));

Re-exports

pub use before_after::*;
pub use iter::*;
pub use NthWeekday::*;
pub use Month::*;

Modules

BeforeAfterDate
A selection of pre-defined holidays provided for convenience
Module provides an iterator over the annual occurrences of a Holiday

Macros

Macro to create Holiday
Macro to create a pub const Holiday

Structs

ISO 8601 calendar date with time zone.
ISO 8601 combined date and time with time zone.
A fixed day of the month (e.g.: March 31)
An annually repeating calendar date. Can be either a fixed date (e.g., April 1) or an nth weekday of the month (e.g., 4th Thursday in November)
The local timescale. This is implemented via the standard time crate.
ISO 8601 calendar date without timezone. Allows for every proleptic Gregorian date from Jan 1, 262145 BCE to Dec 31, 262143 CE. Also supports the conversion from ISO 8601 ordinal and week date.
Nth weekday of a month (e.g.: Second Tuesday in October)

Enums

Holiday Date type
A convenience enum for specifiying the month (January = 1)
The nth ocurrence of a weekday in a month.
The day of week.

Traits

The common set of methods for date component.