time_t in seconds

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

    #1

    time_t in seconds

    i've read recently that time_t doesn't have to be in second resolution
    but if it isn't, then what resolution could it be in?

    microseconds, milliseconds, are all valid?

    also, does anyone know of an implementation
    that does not use second resolution for a time_t?
  • Martin Ambuhl

    #2
    Re: time_t in seconds

    j0mbolar wrote:
    [color=blue]
    > i've read recently that time_t doesn't have to be in second resolution
    > but if it isn't, then what resolution could it be in?
    >
    > microseconds, milliseconds, are all valid?[/color]

    It doesn't have to even be a linear metric.

    Comment

    • Gordon Burditt

      #3
      Re: time_t in seconds

      >i've read recently that time_t doesn't have to be in second resolution[color=blue]
      >but if it isn't, then what resolution could it be in?[/color]

      time_t is not required to be represented as a number of <time unit>
      since <epoch>. That said, if it IS represented as a number of <time
      unit> since <epoch>, any time unit, regardless of how silly, and
      any epoch is acceptable. It is a quality-of-implementation issue
      that times near to now should be representable, and with fairly
      decent resolution (an 8-bit integer counter of geologic ages would
      be considered poor here, as would a 32-bit number of picoseconds
      since the beginning of the universe. Putting the epoch at the END
      of the universe is also problematical since I don't think anyone
      knows when that is relative to now. The same applies to putting
      it as the day of the assassination of World President Saddam Hussein).

      One possible representation of time_t is:
      hhHHSSMMmmddyyy y
      substitute decimal digits for the values, then treat it as a decimal
      integer. A time_t needs more than 48 bits for this representation.
      yyyy = year (Y10K problem here!!)
      mm = month (1-12)
      dd = day of month (1-31)
      HH = hour (0-24)[*]
      MM = minute (0-60)[*]
      SS = second (0-60)[*]
      hh = hundredths of seconds (0-99)
      [*] Some of these limits may seem a bit strange to allow for
      leap seconds.

      Note that the fields are put in a decidedly non-endian order, so
      the result you get from adding or subtracting them is essentially
      useless, and even comparing them as integers doesn't tell you which
      comes first unless they happen to both be in the same second.
      [color=blue]
      >microseconds , milliseconds, are all valid?[/color]

      Yes, as are nano-fortnights and a big integer type that packs the
      28 characters of "Sat Apr 17 19:58:47 CDT 2004" into it.
      [color=blue]
      >also, does anyone know of an implementation
      >that does not use second resolution for a time_t?[/color]

      Microsoft systems such as MS-DOS used a bitfield representation of
      year, month, day, hour, minute, and seconds for file date
      representations . I don't think they used it as a time_t, though.
      BSD Unix systems also have a struct timeval which typically contains
      a time_t and a counter for fractions of seconds. That also isn't
      actually used as a time_t.

      Gordon L. Burditt

      Comment

      • Keith Thompson

        #4
        Re: time_t in seconds

        gordonb.ysiqe@b urditt.org.org (Gordon Burditt) writes:
        [...][color=blue]
        > One possible representation of time_t is:
        > hhHHSSMMmmddyyy y
        > substitute decimal digits for the values, then treat it as a decimal
        > integer. A time_t needs more than 48 bits for this representation.
        > yyyy = year (Y10K problem here!!)
        > mm = month (1-12)
        > dd = day of month (1-31)
        > HH = hour (0-24)[*]
        > MM = minute (0-60)[*]
        > SS = second (0-60)[*]
        > hh = hundredths of seconds (0-99)
        >
        >[*] Some of these limits may seem a bit strange to allow for
        > leap seconds.[/color]

        Small quibble: to allow for leap seconds, it's sufficient to make the
        range of SS 0-60; MM can be 0-59, and HH can be 0-23.

        --
        Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
        San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
        Schroedinger does Shakespeare: "To be *and* not to be"

        Comment

        • Simon Biber

          #5
          Re: time_t in seconds

          "Gordon Burditt" <gordonb.ysiqe@ burditt.org.org > wrote:[color=blue]
          > One possible representation of time_t is:
          > hhHHSSMMmmddyyy y
          > substitute decimal digits for the values, then treat it as a decimal
          > integer. A time_t needs more than 48 bits for this representation.
          > yyyy = year (Y10K problem here!!)
          > mm = month (1-12)
          > dd = day of month (1-31)
          > HH = hour (0-24)[*]
          > MM = minute (0-60)[*]
          > SS = second (0-60)[*]
          > hh = hundredths of seconds (0-99)[/color]

          typedef long long time_t;

          double difftime(time_t a, time_t b)
          {
          double year = (a % 10000
          - b % 10000) * 31556952.0;
          double month = (a % 100000000 / 1000000
          - b % 100000000 / 1000000) * 2629746.0;
          double day = (a % 1000000 / 10000
          - b % 1000000 / 10000) * 86400.0;
          double hour = (a % 100000000000000 / 1000000000000
          - b % 100000000000000 / 1000000000000) * 3600.0;
          double minute = (a % 10000000000 / 100000000
          - b % 10000000000 / 100000000) * 60.0;
          double second = (a % 1000000000000 / 10000000000
          - b % 1000000000000 / 10000000000);
          double hundredth = (a / 100000000000000
          - b / 100000000000000 ) / 100.0;
          return year + month + day + hour + minute + second + hundredth;
          }

          The values for month and year are for an average year, but they should
          actually depend on the year in question. Argh!

          --
          Simon.


          Comment

          • Peter Pichler

            #6
            Re: time_t in seconds

            "Gordon Burditt" <gordonb.ysiqe@ burditt.org.org > wrote:[color=blue]
            > One possible representation of time_t is:
            > hhHHSSMMmmddyyy y[/color]
            ....[color=blue]
            > yyyy = year (Y10K problem here!!)
            > mm = month (1-12)
            > dd = day of month (1-31)
            > HH = hour (0-24)[*]
            > MM = minute (0-60)[*]
            > SS = second (0-60)[*]
            > hh = hundredths of seconds (0-99)[/color]
            ....[color=blue]
            > Note that the fields are put in a decidedly non-endian order[/color]

            Isn't there a precedent for this representation already? :-)
            [color=blue][color=green]
            > >microseconds , milliseconds, are all valid?[/color]
            >
            > Yes, as are nano-fortnights and a big integer type that packs the
            > 28 characters of "Sat Apr 17 19:58:47 CDT 2004" into it.[/color]

            A colleague of mine has had a teacher of physics who insisted on
            converting everything to elementary units.

            Stones, furlongs and fortnights.

            Peter


            Comment

            • Dan Pop

              #7
              Re: time_t in seconds

              In <2d31a9f9.04041 71502.2aa20cae@ posting.google. com> j0mbolar@engine er.com (j0mbolar) writes:
              [color=blue]
              >also, does anyone know of an implementation
              >that does not use second resolution for a time_t?[/color]

              I have yet to hear about one. I guess there was far too much existing
              practice in having time_t as a second offset from one epoch or another
              (the MSDOS epoch used to be 1980.1.1 on the early implementations , IIRC)
              that no one (or practically no one) bothered to reinvent this wheel.

              Dan
              --
              Dan Pop
              DESY Zeuthen, RZ group
              Email: Dan.Pop@ifh.de

              Comment

              Working...