File 2588-stdlib-Correct-calendar-rfc3339_to_system_time.patch of Package erlang
From 6ec9c3d42310671f62ff080bc325fb29fa13d3fa Mon Sep 17 00:00:00 2001
From: Hans Bolinder <hasse@erlang.org>
Date: Thu, 27 Feb 2020 15:18:13 +0100
Subject: [PATCH] stdlib: Correct calendar:rfc3339_to_system_time()
See also https://bugs.erlang.org/browse/ERL-1182.
---
lib/stdlib/src/calendar.erl | 8 ++++----
lib/stdlib/test/calendar_SUITE.erl | 3 ++-
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/lib/stdlib/src/calendar.erl b/lib/stdlib/src/calendar.erl
index 3a8fe2211b..ef6d1882e6 100644
--- a/lib/stdlib/src/calendar.erl
+++ b/lib/stdlib/src/calendar.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1996-2019. All Rights Reserved.
+%% Copyright Ericsson AB 1996-2020. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -369,7 +369,7 @@ rfc3339_to_system_time(DateTimeString, Options) ->
IsFractionChar = fun(C) -> C >= $0 andalso C =< $9 orelse C =:= $. end,
{FractionStr, UtcOffset} = lists:splitwith(IsFractionChar, TimeStr),
Time = datetime_to_system_time(DateTime),
- Secs = Time - offset_adjustment(Time, second, UtcOffset),
+ Secs = Time - offset_string_adjustment(Time, second, UtcOffset),
check(DateTimeString, Options, Secs),
ScaledEpoch = erlang:convert_time_unit(Secs, second, Unit),
ScaledEpoch + copy_sign(fraction(Unit, FractionStr), ScaledEpoch).
@@ -689,13 +689,13 @@ offset(OffsetOption, Secs0) when OffsetOption =:= "";
offset(OffsetOption, _Secs) ->
OffsetOption.
+offset_adjustment(Time, Unit, "") ->
+ local_offset(Time, Unit);
offset_adjustment(Time, Unit, OffsetString) when is_list(OffsetString) ->
offset_string_adjustment(Time, Unit, OffsetString);
offset_adjustment(_Time, Unit, Offset) when is_integer(Offset) ->
erlang:convert_time_unit(Offset, Unit, second).
-offset_string_adjustment(Time, Unit, "") ->
- local_offset(Time, Unit);
offset_string_adjustment(_Time, _Unit, "Z") ->
0;
offset_string_adjustment(_Time, _Unit, "z") ->
diff --git a/lib/stdlib/test/calendar_SUITE.erl b/lib/stdlib/test/calendar_SUITE.erl
index 224c0d5625..bea5a217db 100644
--- a/lib/stdlib/test/calendar_SUITE.erl
+++ b/lib/stdlib/test/calendar_SUITE.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1997-2019. All Rights Reserved.
+%% Copyright Ericsson AB 1997-2020. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -223,6 +223,7 @@ rfc3339(Config) when is_list(Config) ->
{'EXIT', _} = (catch do_format_z(253402300799+1, [])),
{'EXIT', _} = (catch do_parse("9999-12-31T23:59:60Z", [])),
{'EXIT', _} = (catch do_format_z(253402300799*1000000000+999999999+1, Ns)),
+ {'EXIT', _} = (catch do_parse("2010-04-11T22:35:41", [])), % OTP-16514
253402300799 = do_parse("9999-12-31T23:59:59Z", []),
"0000-01-01T00:00:00Z" = test_parse("0000-01-01T00:00:00.0+00:00"),
--
2.16.4