[前][次][番号順一覧][スレッド一覧]

ruby-changes:65274

From: Nobuyoshi <ko1@a...>
Date: Tue, 16 Feb 2021 20:34:40 +0900 (JST)
Subject: [ruby-changes:65274] 9ef66ce3fc (master): strftime.c: support unknown offset UTC in RFC 3339 [Feature #17544]

https://git.ruby-lang.org/ruby.git/commit/?id=9ef66ce3fc

From 9ef66ce3fcfee06d628b611dbc22026d7cc72d0e Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Fri, 15 Jan 2021 17:19:18 +0900
Subject: strftime.c: support unknown offset UTC in RFC 3339 [Feature #17544]

In RFC 3339, -00:00 is used for the time in UTC is known, but the
offset to local time is unknown.  Support that representation by
`-` flag for `z`.
---
 strftime.c             | 2 +-
 test/ruby/test_time.rb | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/strftime.c b/strftime.c
index f4180fd..88cdb21 100644
--- a/strftime.c
+++ b/strftime.c
@@ -547,7 +547,7 @@ rb_strftime_with_timespec(VALUE ftime, const char *format, size_t format_len, https://github.com/ruby/ruby/blob/trunk/strftime.c#L547
 			else {
 				off = NUM2LONG(rb_funcall(vtm->utc_offset, rb_intern("round"), 0));
 			}
-			if (off < 0) {
+			if (off < 0 || (off == 0 && (flags & BIT_OF(LEFT)))) {
 				off = -off;
 				sign = -1;
 			}
diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb
index b264e7f..4e8689b 100644
--- a/test/ruby/test_time.rb
+++ b/test/ruby/test_time.rb
@@ -920,6 +920,11 @@ class TestTime < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_time.rb#L920
     assert_equal("+09:00", t.strftime("%:z"))
     assert_equal("+09:00:01", t.strftime("%::z"))
     assert_equal("+09:00:01", t.strftime("%:::z"))
+
+    assert_equal("+0000", t2000.strftime("%z"))
+    assert_equal("-0000", t2000.strftime("%-z"))
+    assert_equal("-00:00", t2000.strftime("%-:z"))
+    assert_equal("-00:00:00", t2000.strftime("%-::z"))
   end
 
   def test_strftime_padding
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]