From 8ec20295ba052e5666fc77b66c09445233943814 Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Mon, 26 Nov 2018 13:12:26 +0100 Subject: stdlib: Let calendar:system_time_to_rfc3339() keep fractions RFC3339 mentions in paragraph 5.1 that if certain conditions are fulfilled, then sorting date and time strings results in a time-ordered sequence. One of the conditions is that the strings must have the same number of fractional second digits. This commits makes sure this is indeed the case. --- lib/stdlib/src/calendar.erl | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'lib/stdlib/src') diff --git a/lib/stdlib/src/calendar.erl b/lib/stdlib/src/calendar.erl index 9a600c1972..bb5d450cd6 100644 --- a/lib/stdlib/src/calendar.erl +++ b/lib/stdlib/src/calendar.erl @@ -693,14 +693,11 @@ local_offset(SystemTime, Unit) -> UniversalSecs = datetime_to_gregorian_seconds(UniversalTime), LocalSecs - UniversalSecs. +fraction_str(1, _Time) -> + ""; fraction_str(Factor, Time) -> - case Time rem Factor of - 0 -> - ""; - Fraction -> - FS = io_lib:fwrite(".~*..0B", [log10(Factor), abs(Fraction)]), - string:trim(FS, trailing, "0") - end. + Fraction = Time rem Factor, + io_lib:fwrite(".~*..0B", [log10(Factor), abs(Fraction)]). fraction(second, _) -> 0; -- cgit v1.2.3