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

ruby-changes:64835

From: Nobuyoshi <ko1@a...>
Date: Tue, 12 Jan 2021 17:08:31 +0900 (JST)
Subject: [ruby-changes:64835] b017848f8a (master): Show seconds of utc_offset if not zero

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

From b017848f8a9c907be07f51d6ae6304bff9950594 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Tue, 12 Jan 2021 17:00:14 +0900
Subject: Show seconds of utc_offset if not zero


diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb
index 3f5cb9d..e49753e 100644
--- a/test/ruby/test_time.rb
+++ b/test/ruby/test_time.rb
@@ -584,6 +584,10 @@ class TestTime < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_time.rb#L584
 
     t2000 = get_t2000.localtime(9*3600) + 1/10r
     assert_equal("2000-01-01 09:00:00.1 +0900", t2000.inspect)
+
+    t2000 = get_t2000
+    assert_equal("2000-01-01 09:12:00 +0912", t2000.localtime(9*3600+12*60).inspect)
+    assert_equal("2000-01-01 09:12:34 +091234", t2000.localtime(9*3600+12*60+34).inspect)
   end
 
   def assert_zone_encoding(time)
diff --git a/time.c b/time.c
index f2f5d17..a395274 100644
--- a/time.c
+++ b/time.c
@@ -4099,7 +4099,14 @@ time_inspect(VALUE time) https://github.com/ruby/ruby/blob/trunk/time.c#L4099
         rb_str_cat_cstr(str, " UTC");
     }
     else {
-        rb_str_concat(str, strftimev(" %z", time, rb_usascii_encoding()));
+        /* ?TODO: subsecond offset */
+        long off = NUM2LONG(rb_funcall(tobj->vtm.utc_offset, rb_intern("round"), 0));
+        char sign = (off < 0) ? (off = -off, '-') : '+';
+        int sec = off % 60;
+        int min = (off /= 60) % 60;
+        off /= 60;
+        rb_str_catf(str, " %c%.2d%.2d", sign, (int)off, min);
+        if (sec) rb_str_catf(str, "%.2d", sec);
     }
     return str;
 }
-- 
cgit v0.10.2


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

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