Re: [R] strptime and "impossible" dates

About this list Date view Thread view Subject view Author view Attachment view

From: Prof Brian Ripley (ripley@stats.ox.ac.uk)
Date: Wed 25 Jul 2001 - 07:26:33 EST


Message-id: <Pine.LNX.4.31.0107242222530.1248-100000@gannet.stats>

On Tue, 24 Jul 2001, David Kane <David Kane wrote:

> Typically, when I use strptime with "impossible" dates I get an NA, which is
> what I expect.
>
> > version
> _
> platform sparc-sun-solaris2.6
> arch sparc
> os solaris2.6
> system sparc, solaris2.6
> status
> major 1
> minor 3.0
> year 2001
> month 06
> day 22
> language R
> > strptime("20001132", format = "%Y%m%d")
> [1] "NA"
>
> But this is not always the case, consider the impossible case of November 31, 2000
>
> > strptime("20001131", format = "%Y%m%d")
> [1] "2000-12-01"
>
> Shouldn't the answer here be NA? I would submit this as a bug except that I
> suspect that the problem is my misunderstanding of the role of seconds and time
> zones is this function . . .

> Thanks for any pointers. I have read the help pages and the excellent
> discussion in the recent R Newsletter.

It depends on the system's strptime. But it would be usual for
out-of-range dates to get normalized as you saw. In general `invalid'
local times (POSIXlt structures) are fixed if they are not seriously
adrift.

-- 
Brian D. Ripley,                  ripley@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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Wed 10 Mar 2004 - 08:18:21 EST