Skip to content

Instantly share code, notes, and snippets.

@dholstius
Created September 20, 2012 19:43
Show Gist options
  • Save dholstius/3757916 to your computer and use it in GitHub Desktop.
Save dholstius/3757916 to your computer and use it in GitHub Desktop.
Wrapper for fasttime::fast.POSIXct
#' fast_POSIXct
#'
#' Quickly converts 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) {
require(fasttime)
stopifnot(is.character(x))
GMT <- fasttime::fastPOSIXct(x, tz='GMT')
epoch <- as.numeric(GMT)
t0 <- '1970-01-01'
z <- as.POSIXct(epoch, tz=tz, origin=t0)
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