| Title: | Working with Canadian Dates |
|---|---|
| Description: | Convenience date tools for identifying weekends, business days, and Canadian holidays, including R wrappers for the 'Canada Holidays' API <https://canada-holidays.ca/>. |
| Authors: | Adam Shen [aut, cph, cre] |
| Maintainer: | Adam Shen <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0.9000 |
| Built: | 2026-05-14 05:16:35 UTC |
| Source: | https://github.com/adamoshen/holideh |
Count the number of business days between a range of dates, inclusively.
count_bizdays(from, to, holidays, weekend = c("Sat", "Sun"))count_bizdays(from, to, holidays, weekend = c("Sat", "Sun"))
from |
The beginning of the date range. |
to |
The end of the date range. |
holidays |
A vector of dates that are holidays. |
weekend |
A character vector of three-letter abbreviations of weekday names indicating days
that should be considered a weekend. Acceptable values are: |
Holiday dates can be obtained using get_holidays(), get_province(), or by defining a custom
vector of holidays.
A single number.
is_bizday(), is_holiday(), is_weekend()
library(lubridate) winter_holidays <- ymd(c("2025-12-25", "2025-12-26")) count_bizdays(from = ymd("2025-12-20"), to = ymd("2025-12-31"), holidays = winter_holidays)library(lubridate) winter_holidays <- ymd(c("2025-12-25", "2025-12-26")) count_bizdays(from = ymd("2025-12-20"), to = ymd("2025-12-31"), holidays = winter_holidays)
Get all holidays for a given year. Best used for obtaining a list of federal holidays.
get_holidays(year = NULL, federal = NULL, optional = NULL)get_holidays(year = NULL, federal = NULL, optional = NULL)
year |
The year for which holidays should be retrieved, between 2013 and 2038. The default,
|
federal |
A boolean indicating whether only federal holidays should be retrieved. The
default, |
optional |
A boolean indicating whether optional (non-legislated) holidays should be
retrieved. The default, |
A tibble with columns:
<date> The date when the holiday occurs.
<date> The date when the holiday is observed (celebrated). For example,
if Christmas Day falls on a Sunday, it is observed (celebrated) on the proceeding Monday.
<chr> The name of the holiday, in English.
<chr> The name of the holiday, in French.
<lgl> Whether the holiday is a federal holiday.
<int> The id of the holiday.
<list> A list of tibbles containing information on the provinces observing
the holiday and source links.
get_province(), Canada Holidays API
if (interactive()) { get_holidays() }if (interactive()) { get_holidays() }
Get all holidays for a given year, for a province or territory. Best used to obtain holiday information for a specific province or territory.
get_province(province, year = NULL, optional = NULL)get_province(province, year = NULL, optional = NULL)
province |
The two letter abbreviation for a province/territory (case-sensitive). |
year |
The year for which holidays should be retrieved, between 2013 and 2038. The default,
|
optional |
A boolean indicating whether optional (non-legislated) holidays should be
retrieved. The default, |
Province and territory codes:
Alberta: "AB"
British Columbia: "BC"
Manitoba: "MB"
New Brunswick: "NB"
Newfoundland and Labrador: "NL"
Nova Scotia: "NS"
Northwest Territories: "NT"
Nunavut: "NU"
Ontario: "ON"
Prince Edward Island: "PE"
Quebec: "QC"
Saskatchewan: "SK"
Yukon: "YT"
A tibble with columns:
<date> The date when the holiday occurs.
<date> The date when the holiday is observed (celebrated). For example,
if Christmas Day falls on a Sunday, it is observed (celebrated) on the proceeding Monday.
<chr> The name of the holiday, in English.
<chr> The name of the holiday, in French.
<lgl> Whether the holiday is a federal holiday.
<int> The id of the holiday.
<chr> The abbreviated province/territory code.
<chr> The name of the province/territory, in English.
<chr> The name of the province/territory, in French.
<list> A list containing a link to the information source.
get_holidays(), Canada Holidays API
if (interactive()) { get_province(province = "ON") }if (interactive()) { get_province(province = "ON") }
In a vector of dates, detect the business days (i.e. exclude holidays and weekends).
is_bizday(x, holidays, weekend = c("Sat", "Sun"))is_bizday(x, holidays, weekend = c("Sat", "Sun"))
x |
A vector of dates or date-times. If date-times are supplied, the date component will be extracted. |
holidays |
A vector of dates that are holidays. |
weekend |
A character vector of three-letter abbreviations of weekday names indicating days
that should be considered a weekend. Acceptable values are: |
Holiday dates can be obtained using get_holidays(), get_province(), or by defining a custom
vector of holidays.
A logical vector of length equal to x.
is_holiday(), is_weekend(), count_bizdays()
library(lubridate) dates <- seq.Date(from = ymd("2025-12-20"), to = ymd("2025-12-31"), by = "1 day") winter_holidays <- ymd(c("2025-12-25", "2025-12-26")) rlang::set_names(is_bizday(dates, holidays = winter_holidays), dates)library(lubridate) dates <- seq.Date(from = ymd("2025-12-20"), to = ymd("2025-12-31"), by = "1 day") winter_holidays <- ymd(c("2025-12-25", "2025-12-26")) rlang::set_names(is_bizday(dates, holidays = winter_holidays), dates)
In a vector of dates, detect the non-business days (holiday or weekend).
is_holiday(x, holidays) is_weekend(x, weekend = c("Sat", "Sun"))is_holiday(x, holidays) is_weekend(x, weekend = c("Sat", "Sun"))
x |
A vector of dates or date-times. If date-times are supplied, the date component will be extracted. |
holidays |
A vector of dates that are holidays. |
weekend |
A character vector of three-letter abbreviations of weekday names indicating days
that should be considered a weekend. Acceptable values are: |
Holiday dates can be obtained using get_holidays(), get_province(), or by defining a custom
vector of holidays.
A logical vector of length equal to x.
library(lubridate) dates <- seq.Date(from = ymd("2025-12-20"), to = ymd("2025-12-31"), by = "1 day") winter_holidays <- ymd(c("2025-12-25", "2025-12-26")) rlang::set_names(is_holiday(dates, holidays = winter_holidays), dates) rlang::set_names(is_weekend(dates), dates)library(lubridate) dates <- seq.Date(from = ymd("2025-12-20"), to = ymd("2025-12-31"), by = "1 day") winter_holidays <- ymd(c("2025-12-25", "2025-12-26")) rlang::set_names(is_holiday(dates, holidays = winter_holidays), dates) rlang::set_names(is_weekend(dates), dates)