[Rd] (PR#9577) bug and patch: strptime first-of-month error in (possibly unsupported use of) "%j" format
Prof Brian Ripley
ripley at stats.ox.ac.uk
Thu Mar 22 12:52:13 CET 2007
The aim was to fix up some unsupported cases in glibc and related
implementations, and clearly we only managed to do so partially.
Thank you: I've applied the change (and a regression test) to 2.5.0-to-be.
On Wed, 21 Mar 2007, jbrzusto at fastmail.fm wrote:
> Full_Name: John Brzustowski
> Version: R-devel-trunk
> OS: linux (problem under Windows too)
> Submission from: (NULL) (74.101.124.238)
>
>
> (This bug was discovered by Phil Taylor, Acadia University.)
> I'm not sure from reading the documentation whether strptime(x, "%j") is meant
> to be supported, but if so, there is a bug which prevents it from working on the
> first day of months after January:
>
>> strptime(31:33, "%j")
> [1] "2007-01-31" NA "2007-02-02"
>
> # the full extent of R's taunting
> strptime(1 + cumsum(c(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30)), "%j")
> [1] NA NA NA NA NA NA NA NA NA NA NA
>>
>
> The problem is an edge-case comparison in datetime.c:glibc_fix(). This
> generates a date like "Jan 32", which validate_tm() catches and NAs.
> (Values of field tm->tm_yday start at 0, not 1.)
> =================================================================================
> PATCH:
>
> --- R/src/main/datetime.c (revision 40860)
> +++ R/src/main/datetime.c (working copy)
> @@ -796,7 +796,7 @@
> if(tm->tm_yday != NA_INTEGER) {
> /* since we have yday, let that take precedence over mon/mday */
> int yday = tm->tm_yday, mon = 0;
> - while(yday > (tmp = days_in_month[mon] +
> + while(yday >= (tmp = days_in_month[mon] +
> ((mon==1 && isleap(1900+tm->tm_year))? 1 : 0))) {
> yday -= tmp;
> mon++;
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
--
Brian D. Ripley, ripley at 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 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-devel
mailing list