0

What is a good way to generate a sequence of times that cross a DST boundary?

For example,

startdst <- ymd_hms("2013-03-10 00:00:00",tz="America/Los_Angeles")
enddst <- ymd_hms("2013-11-03 00:00:00",tz="America/Los_Angeles")

creates times at the start of the transition day to and from DST on the west coast of the USA.

startday <- startdst + minutes(seq(0,to = 24*60, by = 15))
endday <- enddst + minutes(seq(0,to = 24*60, by = 15))

creates instants at 15-minute intervals throughout both days.

That gives me

> head(startday,n=16)
 [1] "2013-03-10 00:00:00 PST" "2013-03-10 00:15:00 PST"
 [3] "2013-03-10 00:30:00 PST" "2013-03-10 00:45:00 PST"
 [5] "2013-03-10 01:00:00 PST" "2013-03-10 01:15:00 PST"
 [7] "2013-03-10 01:30:00 PST" "2013-03-10 01:45:00 PST"
 [9] NA                        NA                       
[11] NA                        NA                       
[13] "2013-03-10 03:00:00 PDT" "2013-03-10 03:15:00 PDT"
[15] "2013-03-10 03:30:00 PDT" "2013-03-10 03:45:00 PDT"

even though 03:00 PDT is only 15 minutes after 01:45 PST. IOW, why are elements [9] through [12] there?

Similarly,

> head(endday,n=16)
 [1] "2013-11-03 00:00:00 PDT" "2013-11-03 00:15:00 PDT"
 [3] "2013-11-03 00:30:00 PDT" "2013-11-03 00:45:00 PDT"
 [5] "2013-11-03 01:00:00 PDT" "2013-11-03 01:15:00 PDT"
 [7] "2013-11-03 01:30:00 PDT" "2013-11-03 01:45:00 PDT"
 [9] "2013-11-03 02:00:00 PST" "2013-11-03 02:15:00 PST"
[11] "2013-11-03 02:30:00 PST" "2013-11-03 02:45:00 PST"
[13] "2013-11-03 03:00:00 PST" "2013-11-03 03:15:00 PST"
[15] "2013-11-03 03:30:00 PST" "2013-11-03 03:45:00 PST"

goes straight from 1:45 PDT to 2:00 PST, even though 75 minutes separates those times. IOW, what happened to 1:00 PST through 1:45 PST?

Incidentally, lubridate knows that:

> diff(endday)
Time differences in mins
 [1] 15 15 15 15 15 15 15 75 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15
[26] 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15
[51] 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15
[76] 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15
attr(,"tzone")
[1] "America/Los_Angeles"

How do I get contiguous instants in contiguous entries?

BTW, this is loosely related to Is there a way to assign DST transitions automatically in lubridate?.

Bill

Community
  • 1
  • 1
Bill
  • 533
  • 1
  • 4
  • 16

1 Answers1

0

Thanks to R sequence of dates with lubridate, I found an answer:

seq(startdst,startdst+hours(4),by="15 min")
seq(enddst,enddst+hours(4),by="15 min")

I don't understand why my original approach failed, though; it seems like it should have given the same answer or thrown an error.

Community
  • 1
  • 1
Bill
  • 533
  • 1
  • 4
  • 16