Skip to content

strptime mysteriously adds a day - 0S-specific: Linux and Windows (so far) (PR#1466)

4 messages · Jason Turner, Martin Maechler, Brian Ripley

#
strptime() mysteriously adds a day to a date, unless the year
is specified.  Tested on:
Linux (RedHat 6.0) - R version 1.4.1 and R-devel.
Windows - R version 1.4.1

Bug isn't found on OpenBSD, R version 1.4.1.

Transcript:

R : Copyright 2002, The R Development Core Team
Version 1.4.1  (2002-01-30)

...
[1] "2002-04-12 22:00:00 NZST"
[1] "2002-04-11 22:00:00 NZST"
_                
platform i586-pc-linux-gnu
arch     i586             
os       linux-gnu        
system   i586, linux-gnu  
status                    
major    1                
minor    4.1              
year     2002             
month    01               
day      30               
language R
platform i586-pc-linux-gnu           
arch     i586                        
os       linux-gnu                   
system   i586, linux-gnu             
status   Under development (unstable)
major    1                           
minor    5.0                         
year     2002                        
month    04                          
day      16                          
language R
_              
platform i386-pc-mingw32
arch     x86            
os       Win32          
system   x86, Win32     
status                  
major    1              
minor    4.1            
year     2002           
month    01             
day      30             
language R
_
platform i386-unknown-openbsd3.0
arch     i386
os       openbsd3.0
system   i386, openbsd3.0
status
major    1
minor    4.1
year     2002
month    01
day      30
language R

  
    
#
Jason> strptime() mysteriously adds a day to a date, unless the year
    Jason> is specified.  Tested on:
    Jason> Linux (RedHat 6.0) - R version 1.4.1 and R-devel.
    Jason> Windows - R version 1.4.1

    Jason> Bug isn't found on OpenBSD, R version 1.4.1.

I confirm the bug (R-devel, Redhat 7.1)
To reproduce, it's sufficient to work with 
"%d %B" or "%d %b" .

What happens is that January and February work okay, and all
months from March produce the problem,

e.g.
[1] "2002-02-28"
[1] "2002-03-20"

Martin
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Thu, 18 Apr 2002, Martin Maechler wrote:

            
The issue is that an unspecified year is assumed *by the IS* to be 1900, a
leap year. I'm not sure why glibc does this when the tm_year field is not
being set, but it confidently says this is day 101 of the year, and that's
the result you get.

The only portable workaround is to give the year: there is (at least in
R-devel) a warning in the help file about this.
#
On Thu, 18 Apr 2002 ripley@stats.ox.ac.uk wrote:

            
Well, I thought that was it, but as 1900 was not a leap year, it's
stranger still.
(For 11 April, BTW.)