Skip to content

Commit

Permalink
Fix rfc3339_to_system_time handling of fractional seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
Maria-12648430 committed Jan 10, 2025
1 parent eda3df1 commit b7f702a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 1 addition & 4 deletions lib/stdlib/src/calendar.erl
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ rfc3339_to_system_time_1(DateTimeIn, Options, Year, Month, Day, Hour, Min, Sec,
Secs = Time - offset_string_adjustment(Time, second, UtcOffset),
check(DateTimeIn, Options, Secs),
ScaledEpoch = erlang:convert_time_unit(Secs, second, Unit),
ScaledEpoch + copy_sign(fraction(Unit, FractionStr), ScaledEpoch).
ScaledEpoch + fraction(Unit, FractionStr).



Expand Down Expand Up @@ -1042,9 +1042,6 @@ fraction(_, "") ->
fraction(Unit, FractionStr) ->
round(factor(Unit) * list_to_float([$0|FractionStr])).

copy_sign(N1, N2) when N2 < 0 -> -N1;
copy_sign(N1, _N2) -> N1.

factor(second) -> 1;
factor(millisecond) -> 1000;
factor(microsecond) -> 1_000_000;
Expand Down
6 changes: 6 additions & 0 deletions lib/stdlib/test/calendar_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,12 @@ rfc3339(Config) when is_list(Config) ->
-1613833200000000 = do_parse("1918-11-11T11:00:00+02:00", Mys),
-1613833200000000 = do_parse("1918-11-11T09:00:00Z", Mys),

%% GH-9279
-1500 = do_parse("1969-12-31T23:59:58.5Z", Ms),
-500 = do_parse("1969-12-31T23:59:59.5Z", Ms),
500 = do_parse("1970-01-01T00:00:00.5Z", Ms),
1500 = do_parse("1970-01-01T00:00:01.5Z", Ms),

"1970-01-01T00:00:00.000000Z" = do_format_z(0, Mys),
"1970-01-01T00:00:01Z" = do_format_z(1, S),
"1970-01-01T00:00:00.001Z" = do_format_z(1, Ms),
Expand Down

0 comments on commit b7f702a

Please sign in to comment.