Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Daylight savings time in lubridate

Tags:

r

time-series

I'm running R 2.15.1 on a Mac with OS X Mountain Lion. I'm trying to use the lubridate package (v 1.1.0) to generate a sequence of times in the US Eastern time zone for the year 2011 at 15 minute intervals. The following seems like it should work:

d0 <- mdy_hms("1/1/2011 5:00:00", tz="UTC")
dspan <- d0 + c(0:35039) * minutes(15)
espan <- with_tz(dspan,tz="America/New_york")

Now, in 2011 daylight savings time began at 2 AM on March 13. The first 16 values of espan on that date are:

espan[(month(espan)==3)&(day(espan)==13)][1:16]

 [1] "00:00:00 EST" "00:15:00 EST" "00:30:00 EST" "00:45:00 EST"
 [5] "01:00:00 EST" "01:15:00 EST" "01:30:00 EST" "01:45:00 EST"
 [9] "03:00:00 EDT" "03:15:00 EDT" "03:30:00 EDT" "03:45:00 EDT"
[13] "04:00:00 EDT" "04:15:00 EDT" "04:30:00 EDT" "04:45:00 EDT"

In the above output I removed the dates to get it to fit here. But it is giving me what I expect. The time one hour after 1 AM EST is 3 AM EDT. However, daylight savings time ended on November 6, and here are the first 16 values of espan on that date:

espan[(month(espan)==11)&(day(espan)==6)][1:16]

 [1] "00:00:00 EDT" "00:15:00 EDT" "00:30:00 EDT" "00:45:00 EDT"
 [5] "01:00:00 EDT" "01:15:00 EDT" "01:30:00 EDT" "01:45:00 EDT"
 [9] "01:00:00 EDT" "01:15:00 EDT" "01:30:00 EDT" "01:45:00 EDT"
[13] "02:00:00 EST" "02:15:00 EST" "02:30:00 EST" "02:45:00 EST"

Why does 1 AM EDT appear twice? Shouldn't the time one hour later than 1 AM EDT be 1 AM EST? Is this a problem with lubridate, or some quirk of the operating system?

like image 278
Ringold Avatar asked Oct 07 '22 19:10

Ringold


1 Answers

I think that is a bug.

> seq(as.POSIXct("2011-11-06 00:15:00", tz='America/New_York'), 
      as.POSIXct('2011-11-06 02:45:00', tz='America/New_York'), 
      by='min')[c(TRUE, rep(FALSE, 14))]

 [1] "2011-11-06 00:15:00 EDT" "2011-11-06 00:30:00 EDT" "2011-11-06 00:45:00 EDT"
 [4] "2011-11-06 01:00:00 EDT" "2011-11-06 01:15:00 EDT" "2011-11-06 01:30:00 EDT"
 [7] "2011-11-06 01:45:00 EDT" "2011-11-06 01:00:00 EST" "2011-11-06 01:15:00 EST"
[10] "2011-11-06 01:30:00 EST" "2011-11-06 01:45:00 EST" "2011-11-06 02:00:00 EST"
[13] "2011-11-06 02:15:00 EST" "2011-11-06 02:30:00 EST" "2011-11-06 02:45:00 EST"
like image 109
GSee Avatar answered Oct 10 '22 03:10

GSee