Re: using mktime()

From: Michael Mair (Michael.Mair_at_invalid.invalid)
Date: 02/21/05


Date: Mon, 21 Feb 2005 15:30:40 +0100


Al Bowers wrote:
> Dave Thompson wrote:
>
>>>>
>>>
>>> No. What the Standard says is that function mktime will bring
>>> all values into range. For example the range for struct tm member
>>>
>>
>>
>> If the call is successful, yes. It (definitely) won't be if the
>> requested time is not representable in time_t, and it's not clear if
>> mktime() is allowed to fail in other cases that the implementor
>> decides are "too hard" -- the comments in the Olson public-domain
>> implementation imply to me that this might have happened.
>>
>>
>>
> Yes, the Standard does not specify anthing on the resulting values of
> the struct tm
> members should and and when an implement of function mktime decides that
> time is
> not representable. The values may be changed or unchanged, in part or
> in total.
>
>>> tm_sec is 0-59. If tm_sec has the value of say -69 the function
>>> mktime will bring tm_sec into range by subtracting 1 from tm_min.
>>>
>>
>>
>> Actually tm_sec is 0-60 to allow for (positive) leap seconds, which
>> are rarely if ever implemented. That is, leap seconds actually happen
>> (for now, there has been discussion of eliminating them) but (most?) C
>> implementations (and systems) just treat them as transient errors.
>> The only people I've heard of actually using them are the ones for
>> whom they were designed -- astronomers and space navigators, and their
>> only contact to most ordinary people, GPS.
>>
>>
> I believe the Standard specifies the representable range as 0-59. I do
> not recall any mention
> of leap seconds in the Standard. Perhaps you are referring to an
> implement that extends
> the Standard. Unfortumately, I will be away from headquarters for a
> week, and not have
> access to the Standard document. Please correct me if I am wrong.

Read it just this weekend in C Unleashed, so I am sure the range
is 0..60; however we can have the look at the standard:

"7.23.1 Components of time
....
4 The range and precision of times representable in clock_t and time_t
are implementation-defined. The tm structure shall contain at least the
following members, in any order. The semantics of the members and their
normal ranges are expressed in the comments.265)
  int tm_sec; // seconds after the minute [0, 60]
  int tm_min; // minutes after the hour [0, 59]
  int tm_hour; // hours since midnight [0, 23]
  int tm_mday; // day of the month [1, 31]
  int tm_mon; // months since January [0, 11]
  int tm_year; // years since 1900
  int tm_wday; // days since Sunday [0, 6]
  int tm_yday; // days since January 1 [0, 365]
  int tm_isdst; // Daylight Saving Time flag

________________________________________________________________________
265) The range [0, 60] for tm_sec allows for a positive leap second.
"

Cheers
  Michael

-- 
E-Mail: Mine is a   gmx dot de   address.


Relevant Pages

  • Re: using mktime()
    ... >> ranges are what you would expect. ... What the Standard says is that function mktime will bring ... mktimeis allowed to fail in other cases that the implementor ... That is, leap seconds actually happen ...
    (comp.lang.c)
  • Re: SEARCH ALL
    ... is limited in its subjects to keys referenced in the KEY ... It MAY well be possible for the implementor to ... That both the documentation and the standard at the time ... I duly reported back to the salesman that it was impossible to ...
    (comp.lang.cobol)
  • Re: Method to force keeping of source
    ... but the data file is? ... the functionality of, LABEL RECORDS ARE STANDARD. ... the implementor, and the way fields of those various USAGEs are distributed ... be meaningful except in the narrow context of the machine on which the file ...
    (comp.lang.cobol)
  • Re: A very *PERSONAL* view of ISO 2002 COBOL for the IBM (mainframe) environment
    ... I very much enjoyed reading Bill Klein's take on the '02 standard. ... Bill noted that in current IBM mainframe COBOL ... and it's *only* in free-form reference format, ... "Margin R" has been whatever the implementor ...
    (comp.lang.cobol)
  • Re: sprintf
    ... There would be no standard if if demons flew from my nose. ... Undefined behavior gives the implementor license to not catch ...
    (comp.lang.c)