Skip to content

Commit

Permalink
Update staging_is_active.R
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Aug 21, 2024
1 parent 6a8d112 commit 42db2b0
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions R/staging_is_active.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,30 @@
#' @family staging
#' @description Check if the stating universe is active.
#' @return `TRUE` if the staging universe is active, `FALSE` otherwise.
#' @param thresholds Character vector of `"%m-%d"` dates that the
#' @param start Character vector of `"%m-%d"` dates that the
#' staging universe becomes active. Staging will then last for a full calendar
#' month until, but not including, the same date a month later.
#' month. For example, if you supply a start date of `"01-15"`,
#' then the staging period will include all days from `"01-15"` through `"02-14"`

Check warning on line 9 in R/staging_is_active.R

View workflow job for this annotation

GitHub Actions / lint

file=R/staging_is_active.R,line=9,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 83 characters.
#' and not include `"02-15"`.
#' @param today Character string with today's date in `"%Y-%m-%d"` format or an
#' object convertible to POSIXlt format.
#' @examples
#' staging_is_active()
staging_is_active <- function(
thresholds = c("01-15", "04-15", "07-15", "10-15"),
start = c("01-15", "04-15", "07-15", "10-15"),
today = Sys.Date()
) {
today <- as.POSIXlt(today, tz = "UTC")
within_freeze <- function(x, today) {
mon <- today$mon + 1L
day <- today$mday
mon == x[1L] && day >= x[2L] || mon == x[1L] + 1L && day < x[2L]
}
thresholds <- strsplit(thresholds, split = "-", fixed = TRUE)
thresholds <- lapply(thresholds, as.integer)
within <- lapply(thresholds, within_freeze, today = today)
any(as.logical(within))
today <- as.POSIXlt(today, tz = "UTC")

Check warning on line 19 in R/staging_is_active.R

View workflow job for this annotation

GitHub Actions / lint

file=R/staging_is_active.R,line=19,col=3,[indentation_linter] Indentation should be 2 spaces but is 3 spaces.
start <- strsplit(start, split = "-", fixed = TRUE)
start <- lapply(start, as.integer)
within <- lapply(start, within_staging, today = today)
any(as.logical(within))
}

within_staging <- function(start, today) {
month <- today$mon + 1L
day <- today$mday
stopifnot(day <= 28L)
(month == start[1L] && day >= start[2L]) ||
(month == start[1L] + 1L && day < start[2L])
}

0 comments on commit 42db2b0

Please sign in to comment.