diff options
author | Nathan Bruning <nathan.bruning@iperity.com> | 2015-01-21 01:10:41 +0100 |
---|---|---|
committer | Nathan Bruning <nathan.bruning@iperity.com> | 2015-01-21 01:10:41 +0100 |
commit | a983df4848cba1f945355a6a9bb8b682b7e7af7d (patch) | |
tree | 38a6adf396fb634c757a7fc2147089be37adb84c /src | |
parent | Merge pull request #410 from weiss/enable-transient-supervisors (diff) |
Fix overflow in XEP-0203 delay: if microseconds exceeded 999499, *** was put in the formatted timestamp
Diffstat (limited to 'src')
-rw-r--r-- | src/jlib.erl | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/jlib.erl b/src/jlib.erl index 9198d23dc..9cafe3215 100644 --- a/src/jlib.erl +++ b/src/jlib.erl @@ -717,7 +717,11 @@ now_to_utc_string({MegaSecs, Secs, MicroSecs}, Precision) -> {{Year, Month, Day}, {Hour, Minute, Second}} = calendar:now_to_universal_time({MegaSecs, Secs, MicroSecs}), - FracOfSec = round(MicroSecs / math:pow(10, 6 - Precision)), + Max = 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, |