Skip to content

Commit

Permalink
Load calendars from JSON files and removed rdas
Browse files Browse the repository at this point in the history
rdas files have been removed.
Calendars now are loaded from JSON files that has the calendar's specification.
All tests and examples had to be adapted to the absence of rda files.
  • Loading branch information
wilsonfreitas committed May 3, 2022
1 parent b033b9b commit 5643af1
Show file tree
Hide file tree
Showing 35 changed files with 1,452 additions and 221 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Suggests:
Imports: methods, utils, jsonlite
Collate:
'R-bizdays-package.r'
'datasets.R'
'calendar.R'
'adjust.date.R'
'bizdays.options.R'
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

* Depends updated to 4.0

* removed data/holidaysANBIMA.rda and data/holidaysB3.rda, calendars are loaded from JSON files

# bizdays 1.0.9

* New function getbizdays which returns the number of business days for specific periods of a year or a month (issue #94)
Expand Down
15 changes: 6 additions & 9 deletions R/adjust.date.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,13 @@ NULL
#' @rdname adjust.date
#' @export
#' @examples
#' cal <- create.calendar("Brazil/ANBIMA", holidaysANBIMA,
#' weekdays = c("saturday", "sunday")
#' )
#' adjust.next("2013-01-01", "Brazil/ANBIMA")
#' adjust.next("2013-01-01", "actual")
adjust.next <- function(dates, cal) UseMethod("adjust.next")

#' @rdname adjust.date
#' @export
#' @examples
#' following("2013-01-01", cal)
#' following("2013-01-01", "actual")
following <- function(dates, cal) UseMethod("following")

#' @export
Expand Down Expand Up @@ -82,7 +79,7 @@ following.Date <- adjust.next.Date
#' @rdname adjust.date
#' @export
#' @examples
#' modified.following("2016-01-31", cal)
#' modified.following("2016-01-31", "actual")
modified.following <- function(dates, cal) UseMethod("modified.following")

#' @export
Expand Down Expand Up @@ -111,13 +108,13 @@ modified.following.Date <- function(dates,
#' @rdname adjust.date
#' @export
#' @examples
#' adjust.previous("2013-01-01", cal)
#' adjust.previous("2013-01-01", "actual")
adjust.previous <- function(dates, cal) UseMethod("adjust.previous")

#' @rdname adjust.date
#' @export
#' @examples
#' preceding("2013-01-01", cal)
#' preceding("2013-01-01", "actual")
preceding <- function(dates, cal) UseMethod("preceding")

#' @export
Expand Down Expand Up @@ -152,7 +149,7 @@ preceding.Date <- adjust.previous.Date
#' @rdname adjust.date
#' @export
#' @examples
#' modified.preceding("2016-01-01", cal)
#' modified.preceding("2016-01-01", "actual")
modified.preceding <- function(dates, cal) UseMethod("modified.preceding")

#' @export
Expand Down
12 changes: 3 additions & 9 deletions R/bizdays.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,10 @@
#' \code{integer} objects representing the amount of business days.
#'
#' @examples
#' create.calendar("Brazil/ANBIMA", holidaysANBIMA,
#' weekdays = c("saturday", "sunday")
#' )
#' bizdays("2013-01-02", "2013-01-31", "Brazil/ANBIMA")
#' bizdays("2013-01-02", "2013-01-31", "actual")
#'
#' # Once you have a default calendar set, cal does not need to be provided
#' bizdays.options$set(default.calendar = "Brazil/ANBIMA")
#' bizdays.options$set(default.calendar = "actual")
#' bizdays("2013-01-02", "2013-01-31")
#'
#' dates <- bizseq("2013-01-01", "2013-01-10")
Expand Down Expand Up @@ -145,10 +142,7 @@ bizdays.Date <- function(from, to,
#' rule is applied.
#'
#' @examples
#' create.calendar("Brazil/ANBIMA", holidaysANBIMA,
#' weekdays = c("saturday", "sunday")
#' )
#' bizdayse("2013-01-02", 3, "Brazil/ANBIMA")
#' bizdayse("2013-01-02", 3, "actual")
#' @export
bizdayse <- function(dates, curd, cal) UseMethod("bizdayse")

Expand Down
2 changes: 1 addition & 1 deletion R/bizdiff.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#'
#' @examples
#' dates <- c("2017-05-10", "2017-05-12", "2017-05-17")
#' bizdiff(dates, "Brazil/ANBIMA")
#' bizdiff(dates, "actual")
#' @export
bizdiff <- function(dates, cal) UseMethod("bizdiff")

Expand Down
5 changes: 1 addition & 4 deletions R/bizseq.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
#' objects with ISO formatted dates.
#'
#' @examples
#' create.calendar("Brazil/ANBIMA", holidaysANBIMA,
#' weekdays = c("saturday", "sunday")
#' )
#' bizseq("2013-01-02", "2013-01-31", "Brazil/ANBIMA")
#' bizseq("2013-01-02", "2013-01-31", "actual")
#' @export
bizseq <- function(from, to, cal) UseMethod("bizseq")

Expand Down
9 changes: 8 additions & 1 deletion R/calendar.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,15 @@
#'
#' @examples
#' # ANBIMA's calendar (from Brazil)
#' holidays <- as.Date(c(
#' "2015-01-01", "2015-02-16", "2015-02-17", "2015-04-03", "2015-04-21",
#' "2015-05-01", "2015-06-04", "2015-09-07", "2015-10-12", "2015-11-02",
#' "2015-11-15", "2015-12-25", "2016-01-01", "2016-02-08", "2016-02-09",
#' "2016-03-25", "2016-04-21", "2016-05-01", "2016-05-26", "2016-09-07",
#' "2016-10-12", "2016-11-02", "2016-11-15", "2016-12-25"
#' ))
#' cal <- create.calendar("Brazil/ANBIMA",
#' holidays = holidaysANBIMA,
#' holidays = holidays,
#' weekdays = c("saturday", "sunday")
#' )
#'
Expand Down
21 changes: 0 additions & 21 deletions R/datasets.R

This file was deleted.

4 changes: 2 additions & 2 deletions R/getdate.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
#'
#' @examples
#' getdate("10th wed", 2018, "actual")
#' getdate("last bizday", 2010:2018, "Brazil/ANBIMA")
#' getdate("last bizday", 2010:2018, "actual")
#' dts <- seq(as.Date("2018-01-01"), as.Date("2018-12-01"), "month")
#' getdate("first bizday", format(dts, "%Y-%m"), "Brazil/ANBIMA")
#' getdate("first bizday", format(dts, "%Y-%m"), "actual")
#' @export
getdate <- function(expr, ref, cal = bizdays.options$get("default.calendar")) {
cal <- check_calendar(cal)
Expand Down
7 changes: 2 additions & 5 deletions R/is.bizday.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@
#' days.
#'
#' @examples
#' create.calendar("Brazil/ANBIMA", holidaysANBIMA,
#' weekdays = c("saturday", "sunday")
#' )
#' is.bizday("2013-01-02", "Brazil/ANBIMA")
#' is.bizday("2013-01-02", "actual")
#'
#' # Once you have a default calendar set, cal does not need to be provided
#' bizdays.options$set(default.calendar = "Brazil/ANBIMA")
#' bizdays.options$set(default.calendar = "actual")
#'
#' dates <- seq(as.Date("2013-01-01"), as.Date("2013-01-05"), by = "day")
#' is.bizday(dates)
Expand Down
19 changes: 3 additions & 16 deletions R/load-buildin-calendars.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,8 @@
#' bizdays::is.bizday("2020-01-01", "Brazil/ANBIMA")
#' @export
load_builtin_calendars <- function() {
create.calendar("actual")
localenv <- new.env()
utils::data("holidaysANBIMA", envir = localenv)
create.calendar("Brazil/ANBIMA", localenv$holidaysANBIMA,
weekdays = c("saturday", "sunday"),
adjust.from = adjust.next, adjust.to = adjust.previous
)
utils::data("holidaysB3", envir = localenv)
create.calendar("Brazil/B3", localenv$holidaysB3,
weekdays = c("saturday", "sunday"),
adjust.from = adjust.next, adjust.to = adjust.previous
)
create.calendar("weekends",
weekdays = c("saturday", "sunday"),
adjust.from = adjust.next, adjust.to = adjust.previous
)
cal_dir <- system.file("extdata", package = "bizdays")
fnames <- list.files(cal_dir, pattern = "json$", full.names = TRUE)
lapply(fnames, load_calendar)
bizdays.options$set(default.calendar = "actual")
}
8 changes: 2 additions & 6 deletions R/offset.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,10 @@
#' @name offset
#'
#' @examples
#' create.calendar("Brazil/ANBIMA", holidaysANBIMA,
#' weekdays = c("saturday", "sunday"),
#' adjust.from = adjust.next, adjust.to = adjust.previous
#' )
#' offset("2013-01-02", 5, "Brazil/ANBIMA")
#' offset("2013-01-02", 5, "actual")
#'
#' # Once you have a default calendar set, cal does not need to be provided
#' bizdays.options$set(default.calendar = "Brazil/ANBIMA")
#' bizdays.options$set(default.calendar = "actual")
#'
#' dates <- seq(as.Date("2013-01-01"), as.Date("2013-01-05"), by = "day")
#' is.bizday(dates)
Expand Down
Binary file removed data/holidaysANBIMA.rda
Binary file not shown.
Binary file removed data/holidaysB3.rda
Binary file not shown.
Loading

0 comments on commit 5643af1

Please sign in to comment.