using mktime()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Al Bowers

    #16
    Re: using mktime()

    Dave Thompson wrote:
    [color=blue][color=green][color=darkred]
    >>>
    >>>[/color]
    >>No. What the Standard says is that function mktime will bring
    >>all values into range. For example the range for struct tm member
    >>
    >>[/color]
    >
    >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
    >implementati on imply to me that this might have happened.
    >
    >
    >[/color]
    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.
    [color=blue][color=green]
    >>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.
    >>
    >>[/color]
    >
    >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
    >implementation s (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.
    >
    >
    >[/color]
    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.
    [color=blue]
    >Presumably you meant -60sec = -1min. -69sec = -2min leaving 51sec.
    >
    >
    >[/color]
    Yes, the result to bring tm_sec into range would be a decrease of 2 in
    tm_min and an
    increase of 120 in tm_sec to bring it's value in range at 51 (120-69).
    [color=blue][color=green]
    >>And on up the ladder, if necessary, until finally tm_mon and
    >>tm_year are determined. Then tm_wday and tm_yday components of the
    >>struct are set appropriately. I would think that a Standard C
    >>that would allow you to add to a time but make reducing it undefined
    >>would be unwise.
    >>
    >>[/color]
    >
    >
    >[/color]

    Al Bowers

    Comment

    • Michael Mair

      #17
      Re: using mktime()



      Al Bowers wrote:[color=blue]
      > Dave Thompson wrote:
      >[color=green][color=darkred]
      >>>>
      >>>
      >>> No. What the Standard says is that function mktime will bring
      >>> all values into range. For example the range for struct tm member
      >>>[/color]
      >>
      >>
      >> 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.
      >>
      >>
      >>[/color]
      > 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.
      >[color=green][color=darkred]
      >>> 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.
      >>>[/color]
      >>
      >>
      >> 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.
      >>
      >>[/color]
      > 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.[/color]

      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.

      Comment

      Working...