Skip to content

Commit

Permalink
Convert to POSIXlt before Date
Browse files Browse the repository at this point in the history
as.Date.POSIXct() does not respect the tzone attribute of the POSIXct
object, so the Date is a UTC date. Convert to POSIXlt first, because
as.Date.POSIXlt() does use the timezone and therefore returns a local
date.

See #53, see #277.
  • Loading branch information
joshuaulrich committed Nov 4, 2018
1 parent bfcbe50 commit cbacd5d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion R/toperiod.R
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function(x) {
# if x is xts, drop HHMMSS from index
if(any(indexClass(x)=='POSIXt')) {
# convert index to Date
index(x) <- as.Date(index(x), tz = indexTZ(x))
index(x) <- as.Date(as.POSIXlt(index(x)))
indexClass(x) <- "Date" # set indexClass to Date
}
if(any(indexClass(x) %in% .classesWithoutTZ)) {
Expand Down

0 comments on commit cbacd5d

Please sign in to comment.