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().