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

From: Prof Brian Ripley <>
Date: Fri 01 Sep 2006 - 13:16:27 GMT

On Fri, 1 Sep 2006, Peter Dalgaard wrote:

> Prof Brian Ripley <> 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 it tells you it was treated as being in UTC, you need to tell subsequent conversions that it is a time in UTC, e.g.

   as.POSIXct(as.POSIXlt(Sys.Date()), tz="UTC")

It is as.POSIXct() that is doing 'dates are treated as midnight in the _current_ timezone ignoring DST', and that is what the documentation of argument 'tz' says will happen. (Since UTC has no DST, it has specified that DST is not in effect, as that is part of a POSIXlt object.)

In your version of R, as.POSIXlt(Sys.Date()) did not specify a timezone (they are optional). Now it does.

> 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.

Which is why I have (I hope) clarified it so tz="UTC" is not needed explicitly anymore.

Brian D. Ripley,        
Professor of Applied Statistics,
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________ mailing list
Received on Sat Sep 02 00:29:29 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 06 Sep 2006 - 11:39:09 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.