R/weekdays.R

Defines functions pts_weekdays

Documented in pts_weekdays

#' Weekdays
#' 
#' Gets the number of weekdays (not Saturday or Sunday) between two dates
#'
#' @param from A date.
#' @param to Another date.
#'
#' @return An integer scalar.
#' @export
#'
#' @examples
#' pts_weekdays()
#' pts_weekdays(as.Date("2000-01-01"), as.Date("1999-12-15"))
#' pts_weekdays(as.Date("2000-01-01"), as.Date("1999-12-15"))
pts_weekdays <- function(from = Sys.Date(), to = dttr::dtt_add_years(from, 1L) - 1) {
  check_date(from)
  check_date(to)

  dates <- dttr::dtt_seq(from, to, units = "days")
  weekdays <- !wday(dates, label = TRUE) %in% c("Sat", "Sun")
  weekdays <- sum(weekdays)
  if(from > to) return(weekdays * -1L)
  weekdays
}
poissonconsulting/poistimesheets documentation built on Jan. 24, 2020, 4:54 a.m.