Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

as.Date() does not respect POSIXct time zones

Okay so here is a subtle "quirk" in the r as.Date function converting from a POSIXct with a timezone, which I am wondering if it is a bug.

> as.POSIXct("2013-03-29", tz = "Europe/London")
[1] "2013-03-29 GMT"
> as.Date(as.POSIXct("2013-03-29", tz = "Europe/London"))
[1] "2013-03-29"

So far no problem, but.....

> as.POSIXct("2013-04-01", tz = "Europe/London")
[1] "2013-04-01 BST"
> as.Date(as.POSIXct("2013-04-01", tz = "Europe/London"))
[1] "2013-03-31"

Anybody seen this? Is this a bug or another quirk? April fools?

like image 590
Thomas Browne Avatar asked Apr 01 '13 12:04

Thomas Browne


1 Answers

The default time zone for as.Date.POSIXct is "UTC" (see the help page). Try as.Date(as.POSIXct("2013-04-01", tz = "Europe/London"),tz = "Europe/London").

like image 137
Roland Avatar answered Nov 11 '22 17:11

Roland