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

ruby-changes:33726

From: akr <ko1@a...>
Date: Sun, 4 May 2014 18:01:26 +0900 (JST)
Subject: [ruby-changes:33726] akr:r45807 (trunk): * lib/time.rb (Time.force_zone!): New private method.

akr	2014-05-04 18:01:19 +0900 (Sun, 04 May 2014)

  New Revision: 45807

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45807

  Log:
    * lib/time.rb (Time.force_zone!): New private method.
      (Time.make_time): Use Time.force_zone!.
      (Time.strptime): Ditto.
      (Time.rfc2822): Ditto.
      (Time.xmlschema): Ditto.
    
    * lib/rss/rss.rb (Time.w3cdtf): Use Time.force_zone!.

  Modified files:
    trunk/ChangeLog
    trunk/lib/rss/rss.rb
    trunk/lib/time.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45806)
+++ ChangeLog	(revision 45807)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun May  4 17:58:12 2014  Tanaka Akira  <akr@f...>
+
+	* lib/time.rb (Time.force_zone!): New private method.
+	  (Time.make_time): Use Time.force_zone!.
+	  (Time.strptime): Ditto.
+	  (Time.rfc2822): Ditto.
+	  (Time.xmlschema): Ditto.
+
+	* lib/rss/rss.rb (Time.w3cdtf): Use Time.force_zone!.
+
 Sun May  4 10:22:59 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* math.c (math_atan2): return values like as expected by C99 if
Index: lib/rss/rss.rb
===================================================================
--- lib/rss/rss.rb	(revision 45806)
+++ lib/rss/rss.rb	(revision 45807)
@@ -28,7 +28,7 @@ class Time https://github.com/ruby/ruby/blob/trunk/lib/rss/rss.rb#L28
             datetime = apply_offset(*(datetime + [off]))
             datetime << usec
             time = Time.utc(*datetime)
-            time.localtime(off) unless zone_utc?(zone)
+            force_zone!(time, zone, off)
             time
           else
             datetime << usec
Index: lib/time.rb
===================================================================
--- lib/time.rb	(revision 45806)
+++ lib/time.rb	(revision 45807)
@@ -174,6 +174,17 @@ class Time https://github.com/ruby/ruby/blob/trunk/lib/time.rb#L174
     end
     private :zone_utc?
 
+    def force_zone!(t, zone, offset=nil)
+      if zone_utc?(zone)
+        t.utc
+      elsif offset ||= zone_offset(zone)
+        t.localtime(offset)
+      else
+        t.localtime
+      end
+    end
+    private :force_zone!
+
     LeapYearMonthDays = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] # :nodoc:
     CommonYearMonthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] # :nodoc:
     def month_days(y, m)
@@ -258,7 +269,7 @@ class Time https://github.com/ruby/ruby/blob/trunk/lib/time.rb#L269
         year, mon, day, hour, min, sec =
           apply_offset(year, mon, day, hour, min, sec, off)
         t = self.utc(year, mon, day, hour, min, sec, usec)
-        t.localtime(off) if !zone_utc?(zone)
+        force_zone!(t, zone, off)
         t
       else
         self.local(year, mon, day, hour, min, sec, usec)
@@ -395,11 +406,7 @@ class Time https://github.com/ruby/ruby/blob/trunk/lib/time.rb#L406
       if seconds = d[:seconds]
         t = Time.at(seconds)
         if zone = d[:zone]
-          if zone_utc?(zone)
-            t.utc
-          elsif offset = zone_offset(zone)
-            t.localtime(offset)
-          end
+          force_zone!(t, zone)
         end
       else
         year = d[:year]
@@ -460,7 +467,7 @@ class Time https://github.com/ruby/ruby/blob/trunk/lib/time.rb#L467
         year, mon, day, hour, min, sec =
           apply_offset(year, mon, day, hour, min, sec, off)
         t = self.utc(year, mon, day, hour, min, sec)
-        t.localtime(off) if !zone_utc?(zone)
+        force_zone!(t, zone, off)
         t
       else
         raise ArgumentError.new("not RFC 2822 compliant date: #{date.inspect}")
@@ -552,7 +559,7 @@ class Time https://github.com/ruby/ruby/blob/trunk/lib/time.rb#L559
           year, mon, day, hour, min, sec =
             apply_offset(year, mon, day, hour, min, sec, off)
           t = self.utc(year, mon, day, hour, min, sec, usec)
-          t.localtime(off) if !zone_utc?(zone)
+          force_zone!(t, zone, off)
           t
         else
           self.local(year, mon, day, hour, min, sec, usec)

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

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