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§

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

Macros§

holiday
Macro to create Holiday
holiday_const
Macro to create a pub const Holiday

Structs§

Date
ISO 8601 calendar date with time zone.
DateTime
ISO 8601 combined date and time with time zone.
DayOfMonth
A fixed day of the month (e.g.: March 31)
Holiday
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)
Local
The local timescale. This is implemented via the standard time crate.
NaiveDate
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.
NthWeekdayOfMonth
Nth weekday of a month (e.g.: Second Tuesday in October)

Enums§

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

Traits§

Datelike
The common set of methods for date component.