Skip to contents

Convert dates and times to SDTM-formatted ISO8601 datetime values

Usage

generate_dtc(
  datetime = NULL,
  date = NULL,
  time = NULL,
  early_hour = "05",
  assume_24_hr_time = FALSE
)

Arguments

datetime

A combined date/time representation (either an ISO8601-formatted character string or a POSIXt object).

date

The date (either an ISO8601-formatted character string, a Date object, or a POSIXt object).

time

The time (an ISO8601-formatted character string)

early_hour

An hour of the day that would suggest times that are not zero padded are from a 12-hour clock instead of a 24-hour clock. (See Details)

assume_24_hr_time

Assume that times of day are from a 24-hour clock even if the hour is an `early_hour`. (See Details)

Value

An SDTM-formatted ISO8601 date-time with "UN:UN:UN" if the time is `NA`. If all inputs are `NA`, then the output is also `NA`.

Details

When times are not zero-padded (for example, "5:12" instead of "05:12"), the probability that they are from a 12-hour clock instead of a 24-hour clock is increased. To minimize the impact of this, when the length of any time character string is 4 or 7 characters, times are less than the `early_hour` will trigger an error under the assumption that generally activities are not happening in the middle of the night. If the times are known to be accurate, setting `assume_24_hr_time=TRUE` will prevent the error and simply pad the strings with zeros.

If a non-NA value is given for `datetime`, then values in `date` and `time` will be ignored.