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

ruby-changes:64896

From: Nobuyoshi <ko1@a...>
Date: Fri, 15 Jan 2021 21:31:32 +0900 (JST)
Subject: [ruby-changes:64896] 5307fab661 (master): [ruby/time] Use Time#strftime to format

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

From 5307fab6619e26e05d791d68c35ceef2e923e8d5 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Fri, 15 Jan 2021 18:17:48 +0900
Subject: [ruby/time] Use Time#strftime to format

https://github.com/ruby/time/commit/6b8cc4799e

diff --git a/lib/time.rb b/lib/time.rb
index 92d24c8..a40e2fe 100644
--- a/lib/time.rb
+++ b/lib/time.rb
@@ -666,30 +666,10 @@ class Time https://github.com/ruby/ruby/blob/trunk/lib/time.rb#L666
   # You must require 'time' to use this method.
   #
   def rfc2822
-    sprintf('%s, %02d %s %0*d %02d:%02d:%02d ',
-      RFC2822_DAY_NAME[wday],
-      day, RFC2822_MONTH_NAME[mon-1], year < 0 ? 5 : 4, year,
-      hour, min, sec) <<
-    if utc?
-      '-0000'
-    else
-      off = utc_offset
-      sign = off < 0 ? '-' : '+'
-      sprintf('%s%02d%02d', sign, *(off.abs / 60).divmod(60))
-    end
+    strftime('%a, %d %b %Y %T ') << (utc? ? '-0000' : strftime('%z'))
   end
   alias rfc822 rfc2822
 
-
-  RFC2822_DAY_NAME = [ # :nodoc:
-    'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'
-  ]
-
-  RFC2822_MONTH_NAME = [ # :nodoc:
-    'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
-    'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
-  ]
-
   #
   # Returns a string which represents the time as RFC 1123 date of HTTP-date
   # defined by RFC 2616:
@@ -706,11 +686,7 @@ class Time https://github.com/ruby/ruby/blob/trunk/lib/time.rb#L686
   # You must require 'time' to use this method.
   #
   def httpdate
-    t = dup.utc
-    sprintf('%s, %02d %s %0*d %02d:%02d:%02d GMT',
-      RFC2822_DAY_NAME[t.wday],
-      t.day, RFC2822_MONTH_NAME[t.mon-1], t.year < 0 ? 5 : 4, t.year,
-      t.hour, t.min, t.sec)
+    getutc.strftime('%a, %d %b %Y %T GMT')
   end
 
   #
-- 
cgit v0.10.2


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

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