ruby-changes:65273
From: Nobuyoshi <ko1@a...>
Date: Tue, 16 Feb 2021 20:34:40 +0900 (JST)
Subject: [ruby-changes:65273] 296a2cab07 (master): Parse "-00:00" as UTC for the round-trip [Feature #17544]
https://git.ruby-lang.org/ruby.git/commit/?id=296a2cab07 From 296a2cab07ce530809ee74dee61180fbb3ca6f91 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Tue, 16 Feb 2021 19:36:20 +0900 Subject: Parse "-00:00" as UTC for the round-trip [Feature #17544] --- test/ruby/test_time_tz.rb | 2 ++ time.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/test/ruby/test_time_tz.rb b/test/ruby/test_time_tz.rb index 3783890..fdc9e11 100644 --- a/test/ruby/test_time_tz.rb +++ b/test/ruby/test_time_tz.rb @@ -261,6 +261,8 @@ class TestTimeTZ < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_time_tz.rb#L261 assert_predicate(Time.new(2019, 1, 1, 0, 0, 0, "UTC"), :utc?) assert_predicate(Time.new(2019, 1, 1, 0, 0, 0, "utc"), :utc?) assert_predicate(Time.new(2019, 1, 1, 0, 0, 0, "Z"), :utc?) + assert_predicate(Time.new(2019, 1, 1, 0, 0, 0, "-00:00"), :utc?) + assert_not_predicate(Time.new(2019, 1, 1, 0, 0, 0, "+00:00"), :utc?) end def test_military_names diff --git a/time.c b/time.c index 050a526..bd79110 100644 --- a/time.c +++ b/time.c @@ -2150,8 +2150,10 @@ utc_offset_arg(VALUE arg) https://github.com/ruby/ruby/blob/trunk/time.c#L2150 if (s[0] != '+' && s[0] != '-') goto invalid_utc_offset; if (!ISDIGIT(s[1]) || !ISDIGIT(s[2])) goto invalid_utc_offset; n += (s[1] * 10 + s[2] - '0' * 11) * 3600; - if (s[0] == '-') + if (s[0] == '-') { + if (n == 0) return UTC_ZONE; n = -n; + } return INT2FIX(n); } else { -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/