aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEvgeny Khramtsov <xramtsov@gmail.com>2015-01-22 11:00:41 +0300
committerEvgeny Khramtsov <xramtsov@gmail.com>2015-01-22 11:00:41 +0300
commit561025ba3250318287b8098837217928d619efa2 (patch)
treef0fb258bcbce2217a82339a5f25ce61db0f08ff8 /src
parentNew command to reload config (EJAB-1140) (diff)
parentIncrement number of seconds on timestamp overflow (diff)
Merge pull request #413 from weiss/fix-timestamp-overflow
Fix timestamp formatting
Diffstat (limited to 'src')
-rw-r--r--src/jlib.erl15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/jlib.erl b/src/jlib.erl
index 9198d23dc..593134176 100644
--- a/src/jlib.erl
+++ b/src/jlib.erl
@@ -717,11 +717,16 @@ 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)),
- 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])).
+ Max = round(math:pow(10, Precision)),
+ 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().