Email List: Xaustin-group-lX
[All Lists]

Re: Defect in XSH strptime

To: austin-group-l@xxxxxxxxxxxxx
Subject: Re: Defect in XSH strptime
From: Geoff Clare <gwc@xxxxxxxxxxxxx>
Date: Mon, 21 May 2007 09:26:14 +0100
References: <200705182116.WAA15353@xxxxxx> <20070519090003.GA15605@xxxxxx> <20070521075807.GC89541@finch-staff-1.thus.net>
Clive D.W. Feather <clive@xxxxxx> wrote, on 21 May 2007:
>
> >> Note the comment about strftime() %C%y producing values larger than
> >> 9999 is at odds with the strftime() description of %C which still
> >> shows a range of [00-99]
> > That's an interesting point.  I wonder what the C Standard folks
> > would say is the required behaviour of strftime() %C when
> > tm_year+1900 is > 9999.  My guess is they would say it is undefined
> > (which means outputting more than two digits is an allowed
> > behaviour, and our note saying %C%y "may" produce values > 9999 is
> > true).
> 
> The wording is:
> 
>        [#3] Each conversion specifier is  replaced  by  appropriate
>        characters   as   described  in  the  following  list.   The
>        appropriate characters  are  determined  using  the  LC_TIME
>        category  of the current locale and by the values of zero or
>        more members of the broken-down time structure pointed to by
>        timeptr,  as  specified  in brackets in the description.  If
>        any of the specified values is outside the normal range, the
>        characters stored are unspecified.
> [...]
>        %C  is  replaced by the year divided by 100 and truncated to
>            an integer, as a decimal number (00-99).  [tm_year]
> 
> The tm_year member doesn't have a "normal range" (this was deliberate),
> therefore the last sentence of [#3] doesn't apply. I would therefore
> take "(00-99)" as being a comment rather than normative text and say that
> the behaviour is defined for all possible values of tm_year.
> 
> If we'd intended to limit years to 0000 to 9999, we would have given
> tm_year a normal range of [-1900, 8099].

Thanks.  So %C being able to output more than 2 digits is definitely
allowed, and is probably required.

> > Applications which need to scan "20070503" as YYYYMMDD should use
> > "%C %y %m %d".
> 
> I'm not convinced - unless you have *specifically* stated otherwise in
> normative text and I've overlooked it - that %C is limited to 2 digits.

That is what AI-041 was all about.  It added the following to the
strptime() description (which you can see in draft 2):

    "In the following list, where numeric ranges of values are given
    (represented by the pattern [x,y]), the value shall fall within
    the range given (both bounds being inclusive), and the number of
    characters scanned (excluding the one matching the next directive)
    shall be no more than the maximum number required to represent any
    value in the range without leading zeros."

-- 
Geoff Clare <g.clare@xxxxxx>
The Open Group, Thames Tower, Station Road, Reading, RG1 1LX, England

<Prev in Thread] Current Thread [Next in Thread>