[erlang-questions] negative diference between two calls to now/0

Per Hedeland per@REDACTED
Mon Feb 5 08:14:34 CET 2007


"Rodrigo Ahumada M." <rodahummont@REDACTED> wrote:
>
>time_lapse({_MgS1, S1, MuS1}, {_MgS2, S2, MuS2}) ->
>  %% calculate the difference of msecs,
>  %% ignore the MegaSecs because always they're zero
>  T1 = S1*1000 + MuS1,
>  T2 = S2*1000 + MuS2,
>  T2 - T1.

>th problem i'm having is some times time_lapse/2 gives me a negative
>number, when calculating WaitedTime and ServedTime.

Try

  T1 = S1*1000000 + MuS1,
  T2 = S2*1000000 + MuS2,
  (T2 - T1) / 1000.

- the third element is *micro*seconds, not milliseconds.

--Per Hedeland



More information about the erlang-questions mailing list