This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: strptime bugs


Thorsten Kukuk wrote on 15/12/01 1:49 PM:
> strptime("12", "%I", &testbuf) should return tm_hour = 12
> The range is [1,12], not [0,11]. But we return tm_hour = 0.

For %I, the range of *input* values is [1,12]. The range of storage
for tm_hour is [0-23] (that's 12:00am -> 11:00pm on a 12-hour clock).
Note that time starts with 12:00am, if you give no %p with a %I,
the range of tm_hour will be [0-11].

> strptime("0091 00 01", "%y %w %W", &testbuf) returns NULL.
>
> strptime("0091", "%y", &testbuf) returns tm_year = 100, but this
> should be tm_year = 91.
> 
> The leading zeros are allowed.

There is actually a Permanent Interpretation already made for this in the
SUS (Note that strptime is "XSI" in the Austin document,
which means it is a part of the UNIX trademark standard but not POSIX).

Here is the text:
" [The person(s) bringing the question write]


     The three failures are different instances of two cases:

      strptime("0091", "%y", &testbuf);
      strptime("00", "%w", &testbuf);

     The failure occurs when strptime tries to convert a string
     with leading
     zeros that make the string longer than its expected length, where the
     "expected" length is the length of the corresponding string returned by
     strftime().  We consider such strings to be invalid data, and
     results based on such data to be undefined.


.....[major editing, cut to conclusion]....

     ....the purpose of the optional leading zeroes is to make
     strptime() more precisely complementary to strftime():  "in order to
     ease the use of identical format strings for strftime() and strptime()"
     (XSH4 version 2, p.616, Application Usage.)  We also cite PIN4.037,
     which was also based on the need for symmetry between the interfaces.

     Applications using strftime() and strptime() have historically used a
     common data format for both.
Section D - The Open Group Decision

The Open Group Final Response:
     A Permanent Interpretation is granted.

Interpretation Date: 09 Feb 96"

This means that "leading zeroes" is to mean "such that strptime is
comoplimentary to strftime".

-- 
Mark S. Brown                                             bmark@us.ibm.com
Senior Technical Staff Member                   512.838.3926  T/L 678.3926
IBM Corporation, Austin, Texas                       Mark Brown/Austin/IBM



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]