R/str_date_formatted.R

Defines functions date_message str_date_formatted

str_date_formatted <- function(date = NA, time_zone = TRUE, 
                               fractional_seconds = TRUE) {
  
  # Get date if not supplied
  if (is.na(date)[1]) date <- lubridate::now(tz = Sys.timezone())
  
  # Format string
  format_date <- if_else(
    fractional_seconds, 
    "%Y-%m-%d %H:%M:%OS3", 
    "%Y-%m-%d %H:%M:%S"
  )
  
  # Format
  x <- format(date, format = format_date, usetz = time_zone)
  
  return(x)
  
}


date_message <- function() stringr::str_c(str_date_formatted(), ": ")

Try the saqgetr package in your browser

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

saqgetr documentation built on Jan. 15, 2021, 2:57 p.m.