now() and arithmetic

Bruce Fitzsimons <>
Mon May 6 06:16:04 CEST 2002


H Matthias,

> Looking at emulator/beam/bif.c, all three are 'small' integers, which
> should mean that they're 28 bits wide.

I couldn't see that but I wasn't sure where to look. Thanks a lot for your
effort.

> Looking at emulator/beam/erl_time_sup.c, in the get_now() function,
> the second counter cannot be more than 999999. The microsecond counter
> depends on gettimeofday(2) behaviour. The linux manpage for this implies
> that the microsecond count will never exceed 999999.

With 20/20 hindsight I can see thats logical - MicroS =1/Million and MegaS =
1 Million. Duh.

> Keep in mind that now() does 'interesting' things if you rapidly
> change the system time. If you really want to know what the system
> thinks the time is, then time/0 may be a better choice.

Its more for TimeToLive calculations, and the complications of converting
time+date from/to a serial time value annoy me enough to (possibly
foolishly) disregard the possibility.
Does TZ actually affect now() on some platforms? Is this the "rapidly
changing system time" or have you had some crazy users playing with the
time?

Many thanks,
Bruce

PS Here are my amazingly simple routines.

now_to_timeval() ->
    now_to_timeval(now()).

now_to_timeval({MegaSecs, Secs, MicroSecs}) ->
    {MegaSecs*1000000+Secs, MicroSecs}.

timeval_to_now({Secs, MicroSecs}) ->
    {trunc(Secs / 1000000), Secs rem 1000000, MicroSecs}.






More information about the erlang-questions mailing list