Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add create_sss_calendar() #3

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
Imports:
bizdays,
dplyr,
janitor,
lubridate,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export(adorn_financial_years)
export(bucket_other)
export(convert_col_date)
export(convert_date)
export(create_sss_calendar)
export(financial_year)
export(make_all_number_percent)
export(make_all_string_numeric)
Expand Down
93 changes: 93 additions & 0 deletions R/date_tools.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,96 @@ financial_year <- function(date, fin_year_start_day = 1, fin_year_start_month =
paste0(lubridate::year(date) - 1, "-", lubridate::year(date))
.default = (paste0(lubridate::year(date), "-", lubridate::year(date) + 1))
}

#' Create standard calendar with Scottish bank holidays
#'
#' This function generates a calendar using Scottish bank holidays for use with
#' `bizdays`.
#' @param date_from Calendar start date
#' @param date_to Calendar end date
#' @export
create_sss_calendar <- function(date_from = "2018-01-01", date_to = "2070-01-01"){
weekend <- c("saturday", "sunday")
bank_holidays_scot <- lubridate::ymd(
c(
"2025-01-02",
"2025-01-01",
"2024-12-26",
"2024-12-25",
"2024-12-02",
"2024-05-27",
"2024-05-06",
"2024-03-29",
"2024-01-02",
"2024-01-01",
"2023-12-26",
"2023-12-25",
"2023-11-30",
"2023-08-07",
"2023-05-29",
"2023-05-08",
"2023-05-01",
"2023-04-07",
"2023-01-03",
"2023-01-02",
"2022-12-27",
"2022-12-26",
"2022-11-30",
"2022-08-01",
"2022-06-03",
"2022-06-02",
"2022-05-02",
"2022-04-15",
"2022-01-04",
"2022-01-03",
"2021-12-28",
"2021-12-27",
"2021-12-27",
"2021-11-30",
"2021-08-02",
"2021-05-31",
"2021-05-03",
"2021-04-02",
"2021-01-04",
"2021-01-01",
"2020-12-28",
"2020-12-25",
"2020-11-30",
"2020-08-03",
"2020-05-08",
"2020-04-10",
"2020-01-02",
"2020-01-01",
"2019-12-26",
"2019-12-25",
"2019-12-02",
"2019-08-05",
"2019-05-27",
"2019-05-06",
"2019-04-22",
"2019-04-19",
"2019-01-02",
"2019-01-01",
"2018-12-26",
"2018-12-25",
"2018-11-30",
"2018-08-06",
"2018-05-28",
"2018-05-07",
"2018-04-02",
"2018-03-30",
"2018-01-02",
"2018-01-01"
)
)

sss_calendar <- bizdays::create.calendar(
'sss_calendar',
holidays = bank_holidays_scot,
weekdays = weekend,
start.date = date_from,
end.date = date_to
)

sss_calendar
}
17 changes: 17 additions & 0 deletions man/create_sss_calendar.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading