R/makeTimestamp.R

Defines functions makeTimestamp

Documented in makeTimestamp

#' Helper function for building ISO-8601 dates
#'
#' `makeTimestame()` generates ISO-8601 formatted
#'   date strings in UTC. This is the format required
#'   to query datetime fields in CCM.
#'
#' @param dateString Character scalar. Names the date
#'   which the function will use to create the formatted
#'   datetime.
#' @returns Character scalar. An ISO-8601 formatted date
#'   in the UTC timezone suitable for use in CCM queries.

makeTimestamp <- function(dateString) {
  # We need to work with datetime objects
  dateObj <- as.POSIXct(dateString)
  # Dates must be in the UTC timezome
  utcDate <- lubridate::with_tz(dateObj, tz = 'UTC')
  # Apply the correct date format
  return(format(utcDate, '%Y-%m-%dT%H:%M:%SZ'))
}

Try the ccmReportR package in your browser

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

ccmReportR documentation built on Feb. 12, 2021, 1:06 a.m.