R/ifc_date.R

Defines functions ifc_date

Documented in ifc_date

#' International Fixed Calendar Date
#'
#' Return a character vector of dates converted from the Gregorian calendar
#' to the 13-month International Fixed Calendar.
#'
#' @param x A date vector.
#' @return A character vector of converted dates.
#' @examples
#' ifc_date(as.Date("2019-01-01"))
#' ifc_date(as.Date("2019-07-04"))
#' ifc_date(as.Date("2019-12-31"))
#' @importFrom lubridate year yday leap_year
#' @export
ifc_date <- function(x) {
  y <- lubridate::year(x)
  z <- lubridate::yday(x)
  m <- sprintf("%02d", z %/% 28 + 1)
  d <- sprintf("%02d", z %% 28)
  paste(y, m, d, sep = "-")
}
kiernann/ifc documentation built on Jan. 1, 2020, 12:55 a.m.