Skip to content

Instantly share code, notes, and snippets.

@dholstius
Created November 27, 2012 20:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dholstius/4156715 to your computer and use it in GitHub Desktop.
Save dholstius/4156715 to your computer and use it in GitHub Desktop.
Quickly convert local timestamps to a POSIXct vector
#' fast_POSIXct
#'
#' Quickly convert local timestamps to a POSIXct vector
#'
#' @param x timestamps (YYYY-mm-dd HH:MM:SS)
#' @param tz local timezone
#' @return POSIXct vector
#' @export
fast_POSIXct <- function(x, tz) {
stopifnot(is.character(x))
require(fasttime)
GMT <- fasttime::fastPOSIXct(x, tz='GMT')
epoch <- as.numeric(GMT)
z <- as.POSIXct(epoch, tz=tz, origin='1970-01-01')
adjusted <- z - as.POSIXlt(z)$isdst * 3600
return(adjusted)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment