From p.dalgaard at biostat.ku.dk  Fri Sep  1 14:40:01 2006
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: 01 Sep 2006 14:40:01 +0200
Subject: [Rd] Date conversion with as.POSIXct and as.POSIXlt (PR#9196)
In-Reply-To: <Pine.LNX.4.64.0609011137060.11470@gannet.stats.ox.ac.uk>
References: <20060901092716.784165866B@slim.kubism.ku.dk>
	<x264g7zyop.fsf@viggo.kubism.ku.dk>
	<Pine.LNX.4.64.0609011137060.11470@gannet.stats.ox.ac.uk>
Message-ID: <x21wqvzroe.fsf@viggo.kubism.ku.dk>

Prof Brian Ripley <ripley at stats.ox.ac.uk> writes:

> On Fri, 1 Sep 2006, Peter Dalgaard wrote:
> 
> [...]
> 
> > I'm not sure any of this is actual bugs (Brian will tell us soon
> > enough), but it does appear at least to be underdocumented.
> 
> (Your message crossed mine.)
> 
> I think it is not a bug and actually explicitly documented in ?as.POSIXlt.  
> What may help those who have not read that documentation is to stick the 
> UTC timezone on the conversion to POSIXlt.  Getting


Hmmm, which part of ?as.POSIXlt didn't I understand? I can't seem to
spot anything pointing to -lt being different from -ct conversion (in
a week-old version of r-devel). What I do see is:


    The 'as.POSIX*' functions convert an object to one of the two
     classes used to represent date/times (calendar dates plus time to
     the nearest second).  They can convert a wide variety of objects,
     including objects of the other class and of classes '"Date"',
     '"date"' (from package 'date' or 'survival'), '"chron"' and
     '"dates"' (from package 'chron') to these classes.  Dates are
     treated as being at midnight UTC.

The last sentence would appear not to be true for as.POSIXlt; dates
are treated as midnight in the _current_ timezone ignoring DST (which
of course is undetectable in Oxford because that _is_ UTC in your
timezone) .

> > as.POSIXlt(Sys.Date())
> [1] "2006-09-01 UTC"
> > as.POSIXct(as.POSIXlt(Sys.Date()))
> [1] "2006-09-01 UTC"
> > as.POSIXct(as.POSIXlt(Sys.Date()), tz="")
> [1] "2006-09-01 01:00:00 GMT Daylight Time"
> 
> might be helpful to non-readers.

I have

> as.POSIXct(as.POSIXlt(Sys.Date()), tz="")
[1] "2006-09-01 01:00:00 CEST"

and of course the whole issue is that 

> dput(as.POSIXlt(Sys.Date(), tz="UTC"))
structure(list(sec = 0, min = 0, hour = 0, mday = 1, mon = 8,
    year = 106, wday = 5, yday = 243, isdst = 0), .Names = c("sec",
"min", "hour", "mday", "mon", "year", "wday", "yday", "isdst"
), class = c("POSIXt", "POSIXlt"))
> dput(as.POSIXlt(Sys.Date()))
structure(list(sec = 0, min = 0, hour = 0, mday = 1, mon = 8,
    year = 106, wday = 5, yday = 243, isdst = 0), .Names = c("sec",
"min", "hour", "mday", "mon", "year", "wday", "yday", "isdst"
), class = c("POSIXt", "POSIXlt"))

are exactly the same -- the tz arg is ignored.

The documentation in ?POSIXlt does have some hints about POSIXlt being
converted to current locale, but I still find the whole thing a bit
unclear.

-- 
   O__  ---- Peter Dalgaard             ?ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907




[Rd] Date conversion with as.POSIXct and as.POSIXlt (PR#9196)
Peter Dalgaard