[R] question about date's

Peter Dalgaard p.dalgaard at biostat.ku.dk
Mon Dec 12 16:15:59 CET 2005


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


> > %W seems to be what is known as "ISO dates" (week starts on Monday),
> > except that
> >
> >>  strftime(as.POSIXlt(as.Date("2005-01-01")), "%U")
> > [1] "00"
> >
> > should be week 53, 2004 according to my printed calendar, and emacs
> > calendar-mode too.
> 
> I _did_ say
> 
> >> That's nothing like as easy, as it is not well-defined.
> 
> The POSIX definition is
> 
> %U
>      Replaced by the week number of the year as a decimal number [00,53].
>      The first Sunday of January is the first day of week 1; days in the
>      new year before this are in week 0.
> 
> %W
>      Replaced by the week number of the year as a decimal number [00,53].
>      The first Monday of January is the first day of week 1; days in the
>      new year before this are in week 0.
> 
> so it is doing what it is documented to do.  I'd take POSIX as more
> definitive than Emacs ....

But not more definitive than the ISO standard, I hope. There are
probably more that 1e8 calendars printed each year according that one. 

The two routines are just not doing the same thing. Calendar-mode goes
by the ISO standard, strftime by POSIX definitions. Of course it all
depends on what the user actually wanted.

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




More information about the R-help mailing list