diff options
author | Holger Weiss <holger@zedat.fu-berlin.de> | 2015-01-21 11:20:26 +0100 |
---|---|---|
committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2015-01-21 11:20:26 +0100 |
commit | 528aabf49c9a5c4de36e9d8e2ca83c089a6a6d88 (patch) | |
tree | 77a0a1c05f6e2818b35170580d00c9da20b63048 /src | |
parent | Don't match integer() against float() value (diff) |
Increment number of seconds on timestamp overflow
Increment the number of seconds and set the fractional part to zero if
the latter is too large.
Diffstat (limited to 'src')
-rw-r--r-- | src/jlib.erl | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/jlib.erl b/src/jlib.erl index 6397335e5..593134176 100644 --- a/src/jlib.erl +++ b/src/jlib.erl @@ -718,14 +718,15 @@ now_to_utc_string({MegaSecs, Secs, MicroSecs}, Precision) -> calendar:now_to_universal_time({MegaSecs, Secs, MicroSecs}), Max = round(math:pow(10, Precision)), - FracOfSec = case round(MicroSecs / math:pow(10, 6 - Precision)) of - Max -> Max - 1; % don't overflow io_lib:format - X -> X - end, - list_to_binary(io_lib:format("~4..0B-~2..0B-~2..0BT~2..0B:~2..0B:~2..0B.~*." - ".0BZ", - [Year, Month, Day, Hour, Minute, Second, - Precision, FracOfSec])). + case round(MicroSecs / math:pow(10, 6 - Precision)) of + Max -> + now_to_utc_string({MegaSecs, Secs + 1, 0}, Precision); + FracOfSec -> + list_to_binary(io_lib:format("~4..0B-~2..0B-~2..0BT" + "~2..0B:~2..0B:~2..0B.~*..0BZ", + [Year, Month, Day, Hour, Minute, Second, + Precision, FracOfSec])) + end. -spec now_to_local_string(erlang:timestamp()) -> binary(). |