Thanks for this clarification. I have learned in the meantime that it is necessary to be very careful when using all these POSIX things. As another example, here is something that made me scratch my head just yesterday:
When I create a sequence of days that happens to start before and ends in daylight savings time, I seem to lose a day: > seq(from = strptime("20030329", format="%Y%m%d"), to= strptime("20030402", format="%Y%m%d"), by="DSTday") [1] "2003-03-29 Westeuropäische Normalzeit" "2003-03-30 Westeuropäische Normalzeit" [3] "2003-03-31 Westeuropäische Sommerzeit" "2003-04-01 Westeuropäische Sommerzeit" > seq(from = strptime("20030329", format="%Y%m%d"), to= strptime("20030402", format="%Y%m%d"), by="day") [1] "2003-03-29 00:00:00 Westeuropäische Normalzeit" "2003-03-30 00:00:00 Westeuropäische Normalzeit" [3] "2003-03-31 01:00:00 Westeuropäische Sommerzeit" "2003-04-01 01:00:00 Westeuropäische Sommerzeit" Again, my expectations might be wrong here, and there will be good reasons why I get this result (my OS again?). But considering all these subtle issues I have encountered so far, personally I can understand why some people suggested that it may be easier to use the chron or date package (especially if you are a beginner, have no prior experience with all these things, and don't want to worry about time zones, DST, or the pitfalls of your OS). At least it was useful for me to cross-check the results I obtained with POSIX with the results using chron. The POSIX classes are a great thing, but as they are much more powerful, they are also more complex and have more things to watch out for and more "traps" to fall in (for me at least ;-)). -Heinrich. > -----Ursprüngliche Nachricht----- > Von: Prof Brian Ripley [mailto:[EMAIL PROTECTED] > Gesendet: Samstag, 22. November 2003 20:56 > An: RINNER Heinrich > Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED] > Betreff: Re: [R] ISOdate() and strptime() > > > Confirmation that this *is* an OS-specific problem: A professional > implementation of the POSIX standard (Solaris) gets all of > these correct. > > Your so-called OS lacks any implementation of strptime, so we > borrowed one > from glibc. Unfortunately, that is buggy, even to the extent that > > unclass(strptime("2003-22-20", format="%Y-%m-%d")) > unclass(strptime("2003 22 20", format="%Y %m %d")) > > give different answers! (And RH8.0 gives the same answers as the > substitute code used on R for Windows.) > > I believe Simon Fear owes the R-developers a public apology > for his (not > properly referenced in the archives) reply to this thread. > > BDR > > On Fri, 14 Nov 2003, Prof Brian Ripley wrote: > > > On Fri, 14 Nov 2003, RINNER Heinrich wrote: > > > > > Dear R-people! > > > > > > I am using R 1.8.0, under Windows XP. > > > While using ISOdate() and strptime(), I noticed the > following behaviour when > > > "wrong" arguments (e.g., months>12) are given to these functions: > > > > > > > ISOdate(year=2003,month=2,day=20) #ok > > > [1] "2003-02-20 13:00:00 Westeuropäische Normalzeit" > > > > ISOdate(year=2003,month=2,day=30) #wrong day, but > returns a value > > > [1] "2003-03-02 13:00:00 Westeuropäische Normalzeit" > > > > ISOdate(year=2003,month=2,day=35) #wrong day, and returns NA > > > [1] NA > > > > ISOdate(year=2003,month=2,day=40) #wrong day, but > returns a value > > > [1] "2003-02-04 01:12:00 Westeuropäische Normalzeit" > > > > ISOdate(year=2003,month=22,day=20) #wrong month, but > returns a value > > > [1] "2003-02-02 21:12:00 Westeuropäische Normalzeit" > > > > > > And almost the same with strptime(): > > > > strptime("2003-02-20", format="%Y-%m-%d") > > > [1] "2003-02-20" > > > > strptime("2003-02-30", format="%Y-%m-%d") > > > [1] "2003-03-02" > > > > strptime("2003-02-35", format="%Y-%m-%d") > > > [1] NA > > > > strptime("2003-02-40", format="%Y-%m-%d") > > > [1] "2003-02-04" > > > > strptime("2003-22-20", format="%Y-%m-%d") > > > [1] NA > > > > > > Is this considered to be a user error ("If you put > garbage in, expect to get > > > garbage out"), or would it be safer to generally return Nas, as in > > > ISOdate(year=2003,month=2,day=35)? > > > > Expect to get the best guess at what you intended, and > expect this to > > depend on your OS. > > > > > > -- > Brian D. Ripley, [EMAIL PROTECTED] > 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 > ______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help