R/datetime-for-url.R

Defines functions datetime_for_url

datetime_for_url <- function(x, .default = NULL, .precision = "ymd") {
  x_sym <- rlang::enexpr(x)
  if (rlang::is_null(x)) {
    return(.default)
  }
  withCallingHandlers(
    warning = function(cnd) {
      rlang::abort(
        glue::glue("Unparseable dates in `{stringr::str_trunc(rlang::expr_deparse(x_sym)[[1]], 25)}`")
      )
    },
    {datetimes <- lubridate::as_datetime(x)}
  )
  lubridate::format_ISO8601(datetimes, precision = .precision)
}

Try the wikkitidy package in your browser

Any scripts or data that you put into this service are public.

wikkitidy documentation built on April 4, 2025, 12:41 a.m.