[R] maptools::sunriset() daylight savings to stardard time change

Prof Brian Ripley ripley at stats.ox.ac.uk
Sun Sep 25 09:01:39 CEST 2011


On Sat, 24 Sep 2011, Folkes, Michael wrote:

> Hello all,
> After beating my head against the wall for a few hours, I give up.
> I have two problems.
> 1. If I use seq() to generate a POSIXct series that crosses a daylight savings to stardard time change I get two values for the first day of change.  The time change is Nov 6,2011.  The value for Nov 7 turns into 23:00 on Nov 6, thus two values for Nov 6.  (see below)
> So I put a time value (noon) into the sequence, that did give me a correct date sequence.

That is as documented.  Did you actually read the help page, which 
says

      The difference between ‘"day"’ and ‘"DSTday"’ is that the former
      ignores changes to/from daylight savings time and the latter takes
      the same clock time each day.

So you asked to increment the clock by 24 hours and not to the same 
time the next day.  I cannot reproduce your results as you have not 
told us your timezone, but I can guess America/Vancouver

> seq(start,end,by='day')
[1] "2011-11-05 00:00:00 PDT" "2011-11-06 00:00:00 PDT"
[3] "2011-11-06 23:00:00 PST"
> seq(start,end,by='DSTday')
[1] "2011-11-05 PDT" "2011-11-06 PDT" "2011-11-07 PST"


>
> 2. When using that modified date sequence in maptools::sunriset(), on day of change to stardard time the sunrise time is shifted by one hour. (i.e. Nov5 8am, Nov6 6am, Nov7 7am)
> I can't fathom why sunriset() is giving me funny results on the day of time change.  I wonder if there is something amiss with how my windows XP is managing time zones perhaps? I would have expected sunriset() to be using just the day value from its dateTime argument, not the time component?
> thanks!
> Michael
>
> __________________________
>
> start <- as.POSIXct("2011-11-05")
> end <- as.POSIXct("2011-11-07")
> date.ser<-seq(start,end,by='day')
> # time change is Nov 6,2011
> date.ser
> #####  Two values for Nov 6 as Nov 7th lost an hour.
> [1] "2011-11-05 00:00:00 PDT" "2011-11-06 00:00:00 PDT"
> [3] "2011-11-06 23:00:00 PST"
>
>
> ### Add noon to correct flexibility for time shift.
> start <- as.POSIXct("2011-11-05 12:00:00")
> end <- as.POSIXct("2011-11-07 12:00:00")
> date.ser<-seq(start,end,by='day')
> date.ser
> [1] "2011-11-05 12:00:00 PDT" "2011-11-06 11:00:00 PST"
> [3] "2011-11-07 11:00:00 PST"
>
> library(maptools)
> nanaimo <- matrix(c(-123+(-57/60),49+11/60), nrow=1)
> sunriset(nanaimo, date.ser, direction="sunrise", POSIXct.out=T)[,2]
> [1] "2011-11-05 08:09:42 PDT" "2011-11-06 06:11:19 PST"
> [3] "2011-11-07 07:12:56 PST"
>
> _______________________________________________________
> Michael Folkes
> Salmon Stock Assessment
> Canadian Dept. of Fisheries & Oceans
> Pacific Biological Station
> 3190 Hammond Bay Rd.
> Nanaimo, B.C., Canada
> V9T-6N7
> Ph (250) 756-7264 Fax (250) 756-7053  Michael.Folkes at dfo-mpo.gc.ca
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


More information about the R-help mailing list