Skip to main content

Crate govuk_bank_holidays

Crate govuk_bank_holidays 

Source
Expand description

§GOV.UK Bank Holidays

This library loads the official list of bank holidays in the United Kingdom as supplied by GOV.UK, which tends to provide this list for only a year or two into the future.

A cached backup list of known bank holidays is stored in this package, though it is not updated often. GOV.UK no longer provide bank holidays for some of the older years still part of this backup list.

Bank holidays differ around the UK. The GOV.UK source currently lists these for 3 “divisions”:

  • England and Wales
  • Scotland
  • Northern Ireland

Methods on BankHolidayCalendar that take a division parameter will consider bank holidays only for the provided division (Some(Division)) or only those that are common to all divisions for None.

§Usage

use govuk_bank_holidays::prelude::*;

let date = chrono::Local::now().date_naive();

// load bank holidays from GOV.UK
let calendar = BankHolidayCalendar::load().await;

// check if the given date is a bank holiday in _all_ divisions
let is_holiday = calendar.is_holiday(&date, None);
println!("Is {date:?} a bank holiday across the UK? {is_holiday}");

// check if the given date is a work day in Northern Ireland
let is_work_day = calendar.is_work_day(&date, Some(Division::NorthernIreland));
println!("Is {date:?} a work day in NI? {is_work_day}");

§Swappable date implementation

  • default or "chrono" feature will use the chrono crate
  • "time" feature will use the time crate
  • implement the PlainDate trait on your own type to use it

Modules§

data_source
Utilities for load and parsing bank holidays from GOV.UK.
prelude
Commonly-used items.

Structs§

BankHoliday
Details of a bank holiday.
BankHolidayCalendar
Calendar of known bank holidays.
MonToFriWorkDays
Typical working week, Monday to Friday.

Enums§

Division
Parts of the UK with shared bank holiday dates.
Error
Possible errors when handling dates and bank holidays.
Weekday
A day of the week from the Gregorian calendar.

Constants§

SOURCE_URL
Default URL to load bank holidays from.

Traits§

PlainDate
Represents a date in the Gregorian calendar without time zone information.
WorkDays
Used by BankHolidayCalendar to determine if a given date is work day or not (typically, but not necessarily, the weekend).