R/feb29-to-28.R

Defines functions dtt_feb29_to_28

Documented in dtt_feb29_to_28

#' Feb 29 to Feb 28
#'
#' Converts Feb 29 to Feb 28th
#'
#' @param x A Date or POSIXct vector.
#'
#' @return The modified Date or POSIXct vector.
#' @export
#'
#' @examples
#' dtt_feb29_to_28(as.Date("2004-02-29"))
dtt_feb29_to_28 <- function(x) {
  chkor(
    chk_s3_class(x, "Date"),
    chk_s3_class(x, "POSIXct")
  )

  wch <- which(dtt_month(x) == 2L & dtt_day(x) == 29L)
  dtt_day(x[wch]) <- 28L
  x
}

Try the dttr2 package in your browser

Any scripts or data that you put into this service are public.

dttr2 documentation built on July 10, 2020, 5:06 p.m.