Skip to contents

std_date standardizes a date vector and returns a vector in Date or POSIXct format, depending on whether there is sub-daily information available in the data.

Usage

std_date(
  x,
  force = c("none", "dt", "dttm"),
  orders = c("mdy", "dmy", "ymd", "mdyr", "dmyr", "ymdr", "mdyR", "dmyR", "ymdR", "mdyT",
    "dmyT", "ymdT", "mdyTz", "dmyTz", "ymdTz", "Tmdyz", "Tdmyz", "Tymdz", "mdyRz",
    "dmyRz", "ymdRz", "mdyrz", "dmyrz", "ymdrz", "Tmdy", "Tdmy", "Tymd", "Tmdyz",
    "Tdmyz", "Tymdz"),
  tz_heuristic = c(5L, 6L),
  warn = TRUE,
  train = TRUE,
  na = na_patterns,
  range_value = c("start", "end", "na"),
  range_sep = c("-", "to", ","),
  ...
)

Arguments

x

A vector of character dates, Dates, or POSIXts

force

Whether to force conversion to Date (force = "dt") or POSIXct (force = "dttm"). The default is no forcing (force = "none").

orders

A character vector of date-time formats. Each order string is a series of formatting characters as listed in base::strptime() but might not include the "%" prefix. For example, "ymd" will match all the possible dates in year, month, day order. Formatting orders might include arbitrary separators. These are discarded. See details of lubridate::parse_date_time() for the implemented formats. If multiple order strings are supplied, the order of applied formats is determined by the select_formats parameter in lubridate::parse_date_time() (if passed via dots).

tz_heuristic

Hours to consider in determining presence of sub-daily information. Only exact hours (i.e. 5:00:00) will be combined. The default corresponds to accidental encoding of the CST-UTC offset as hours.

warn

Should warnings be thrown when necessary? FALSE will suppress all warnings in the conversion process.

train

logical, default TRUE. Whether to train formats on a subset of the input vector. The result of this is that supplied orders are sorted according to performance on this training set, which commonly results in increased performance. Please note that even when train = FALSE (and exact = FALSE, if passed via dots) guessing of the actual formats is still performed on a pseudo-random subset of the original input vector. This might result in ⁠All formats failed to parse⁠ error.See notes in lubridate::parse_date_time().

na

Regular expressions to convert to NA

range_value

The value to use if the date is given as a range; can be the start date, the end date, or fill with NA

range_sep

Separators used for date ranges

...

Additional arguments to pass to convert_to_datetime(). These will, in turn, be passed to further methods, including excel_numeric_to_date(), parse_date_time(), and as.POSIXct().

Value

A Date or POSIXct vector