Re: strptime cannot parse date older than 1938
Re: strptime cannot parse date older than 1938
- Subject: Re: strptime cannot parse date older than 1938
- From: Terry Lambert <email@hidden>
- Date: Thu, 24 Apr 2008 11:58:28 -0700
On Apr 24, 2008, at 3:48 AM, Surf Chen wrote:
Martin Costabel wrote:
Well, on the Mac it only works if you compile for a 64bit
architecture.
Does means that it internally uses the type time_t on mac osx?
You wrote "older than 1938" which is fine in English, but you did not
mean 1938, you meant 2038. If in your program you write 1938 instead
of 38 and %Y instead of %y, everything is OK. If you write 2038 and
%Y, you get the same problem as for 38 and %y.
oh...I make a big written mistake.
Luckily everybody here knows the real meaning.
Whether the date is before or after the Epoch depnds on the value and
the range.
For a 32 bit signed time_t, the range is from -2^31 to 2^31.
<http://www.opengroup.org/onlinepubs/009695399/functions/strptime.html>
The only "bugs" I've seen so far in this thread are:
(1) the 64 bit version of the code should be interpreting a %y 2
digit 38 the same way as the 32 bit code, which is minorly forgivable,
given that the UNIX certification process was done before all of the
64 bit support was dealt with, and humans who care about this sort of
thing should be using %Y and 4 digit dates.
(2) the use of %Y and a 4 digit date on a system with a 32 bit time_t
should arguably cause strptime() to return NULL, indicating a
conversion error.
(3) the value for tm_year should arguably be "38" instead of "69" for
the sample code, unless we are clamping down on pre-Epoch dates (I say
arguably, since the code could be considered correct, either way).
All that said, I think I agree with Sun Microsystems that you should
be using getdate() instead, since it has better conversion
specification and error reporting:
<http://www.opengroup.org/onlinepubs/009695399/functions/getdate.html>
Please file a problem report about strptime().
-- Terry
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden