[H-GEN] time in C/C++
Anthony Towns
aj at azure.humbug.org.au
Wed Dec 29 03:13:57 EST 1999
On Wed, Dec 29, 1999 at 05:02:04PM +1000, Paul Gearon wrote:
> Well I can't comment on leap-seconds (as I don't know when they occur), but
> in terms of determining time differences between consecutive days, then
> difftime is fine.
As long as you take into account things like 00:00:01 1/Jan/2000 -
23:59:59 31/Dec/1999 = 2 seconds, but is probably a whole day as far as
you're concerned.
Converting all your units to whole multiples of 86400 is probably good
enough. In C, something like:
days = timet / 86400; /* discard the remainder */
or norm_timet = timet - (timet % 86400);
or norm_timet = days * 86400;
is probably fine. (with diff = days2 - days1; or
diff = (norm_timet2 - norm_timet1) / 86400)
> (unless leap seconds are a concern? BTW, when ARE they?)
Leap seconds are probably never a concern: your watches/clocks/timers
probably have bigger errors anyway.
They happen when some timekeepers somewhere decide we need one, and get
tacked onto the end of a month sometime. ntp will keep your clock up to
date.
Cheers,
aj
--
Anthony Towns <aj at humbug.org.au> <http://azure.humbug.org.au/~aj/>
I don't speak for anyone save myself. GPG encrypted mail preferred.
``The thing is: trying to be too generic is EVIL. It's stupid, it
results in slower code, and it results in more bugs.''
-- Linus Torvalds
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 350 bytes
Desc: not available
URL: <http://lists.humbug.org.au/pipermail/general/attachments/19991229/48ff35ff/attachment.sig>
More information about the General
mailing list