[asterisk-dev] CDR and daylight savings time

Tilghman Lesher tilghman at mail.jeffandtilghman.com
Mon Jan 1 08:08:17 MST 2007


On Monday 01 January 2007 06:17, Hans Petter Selasky wrote:
> On Monday 01 January 2007 04:07, Kevin P. Fleming wrote:
> > Hans Petter Selasky wrote:
> > > From examining the code, this seems to be the case:
> > >
> > >                 gettimeofday(&cdr->start, NULL);
> > >                 gettimeofday(&cdr->answer, NULL);
> > >                 gettimeofday(&cdr->end, NULL);
> >
> > If you had read the man page for gettimeofday(), you would not have
> > asked this question :-)
> >
> > gettimeofday(), when passed NULL as the second parameter (which we
> > always do and is recommended practice) returns the number of
> > seconds/microseconds since the Unix 'epoch' (January 1, 1970). It does
> > not care about timezones at all, and is not affected by timezones or
> > time shifts. In other words, it returns absolute time, not local time.

<snip>

> Here you clearly see that gettimeofday() is directly connected with the
> local time on the computer. On the other hand, CLOCK_MONOTONIC is not. That
> is what you want to use. Or am I wrong ?

The manpage for gettimeofday(2) returns this nugget, which is probably
explains the problem on your system:

       Under Linux there is some peculiar 'warp clock' semantics associated to
       the settimeofday system call if on the very first call (after  booting)
       that  has  a  non-NULL  tz  argument,  the  tv argument is NULL and the
       tz_minuteswest field is non-zero. In such a case it is assumed that the
       CMOS  clock is on local time, and that it has to be incremented by this
       amount to get UTC system time.  No doubt it is a bad idea to  use  this
       feature.

No doubt when you set up your system, you opted to have the clock set to local
time instead of UTC.  Systems which are set to dual boot with Windows
typically have their clocks set to local time (because that's what Windows
uses), while servers (which need not this weirdness) should have their
hardware clocks set to UTC.

It is further instructive that if you read the libc source to *BSD, you will
find that time(3) is defined by calling gettimeofday(2) with a NULL second
argument.

-- 
Tilghman


More information about the asterisk-dev mailing list