View source: R/derive_vars_dt_dtm_utils.R
get_dt_dtm_range | R Documentation |
Internal helper function to convert a character vector of (possibly partial) dates (dtc
)
into complete dates based on a specified imputation rule (date_imputation
).
get_dt_dtm_range(dtc, create_datetime)
dtc |
A character vector of dates in ISO 8601 format
(e.g.,
|
create_datetime |
return the range in datetime format.
|
The functions replaces missing components in dtc
with the earliest (lower bound)
and latest (upper bound) possible value. Missing year is replaced with "0000"
for the
lower bound and "9999"
for the upper bound.
A list containing two vectors of fully imputed dates
in "YYYY-MM-DD"
or "YYYY-MM-DDThh:mm:ss"
format - the lower and upper limit of the range.
# Get Range from Partial Dates
dtc_dates <- c("2020-02-29", "2021-03")
imputed_dates_first <- admiral:::get_dt_dtm_range(dtc_dates, create_datetime = FALSE)
print(imputed_dates_first)
# Get Range from Partial Datetime
dtc_datetimes <- c("2020-02-29T12:00", "2021-03T14:30")
imputed_datetimes_first <- admiral:::get_dt_dtm_range(dtc_datetimes, create_datetime = TRUE)
print(imputed_datetimes_first)
# Edge case: Return empty character vector for empty input
imputed_empty <- admiral:::get_dt_dtm_range(character(0), create_datetime = TRUE)
print(imputed_empty)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.