Created
November 27, 2012 20:12
-
-
Save dholstius/4156715 to your computer and use it in GitHub Desktop.
Quickly convert local timestamps to a POSIXct vector
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' 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