R/dates.R

Defines functions parse_int_date

Documented in parse_int_date

#' Parse excel-type integer dates
#'
#' @param x numeric vector of Excel-type date values
#' @param date_system which date system to use
#' @return vector of `Date` values
#' @description Input values are dates represented as the number of days since 1900-01-01 (per Excels `DATEVALUE` function)
#'
#' @export
#'
parse_int_date <- function(x, date_system = c("excel", "excel1904", "matlab")) {
	date_system <- match.arg(date_system)
	origin = switch(date_system,
		excel = as.Date("1899-12-30"),
		excel1904 = as.Date("1904-01-01"),
		matlab = as.Date("0000-01-01")-1 )

	retval = NULL
	if(is.numeric(x)){
		retval = as.Date(x, origin = origin ) #"1899-12-30"
	} else {
		stop("input vector should be numeric")
	}
	return(retval)

}
stackcon/rngt documentation built on June 17, 2022, 5:29 p.m.