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

ruby-changes:33760

From: akr <ko1@a...>
Date: Tue, 6 May 2014 18:04:16 +0900 (JST)
Subject: [ruby-changes:33760] akr:r45841 (trunk): * lib/time.rb (Time.make_time): Argument validation code moved from

akr	2014-05-06 18:04:09 +0900 (Tue, 06 May 2014)

  New Revision: 45841

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

  Log:
    * lib/time.rb (Time.make_time): Argument validation code moved from
      Time.parse and Time.strptime.

  Modified files:
    trunk/ChangeLog
    trunk/lib/time.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45840)
+++ ChangeLog	(revision 45841)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue May  6 18:03:05 2014  Tanaka Akira  <akr@f...>
+
+	* lib/time.rb (Time.make_time): Argument validation code moved from
+	  Time.parse and Time.strptime.
+
 Tue May  6 17:27:06 2014  Tanaka Akira  <akr@f...>
 
 	* lib/time.rb (Time.parse): [DOC] Fix an example in the documentation
Index: lib/time.rb
===================================================================
--- lib/time.rb	(revision 45840)
+++ lib/time.rb	(revision 45841)
@@ -246,7 +246,11 @@ class Time https://github.com/ruby/ruby/blob/trunk/lib/time.rb#L246
     end
     private :apply_offset
 
-    def make_time(year, mon, day, hour, min, sec, sec_fraction, zone, now)
+    def make_time(date, year, mon, day, hour, min, sec, sec_fraction, zone, now)
+      if !year && !mon && !day && !hour && !min && !sec && !sec_fraction
+        raise ArgumentError, "no time information in #{date.inspect}"
+      end
+
       usec = nil
       usec = sec_fraction * 1000000 if sec_fraction
       if now
@@ -341,12 +345,9 @@ class Time https://github.com/ruby/ruby/blob/trunk/lib/time.rb#L345
     def parse(date, now=self.now)
       comp = !block_given?
       d = Date._parse(date, comp)
-      if !d[:year] && !d[:mon] && !d[:mday] && !d[:hour] && !d[:min] && !d[:sec] && !d[:sec_fraction]
-        raise ArgumentError, "no time information in #{date.inspect}"
-      end
       year = d[:year]
       year = yield(year) if year && !comp
-      make_time(year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
+      make_time(date, year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
     end
 
     #
@@ -416,12 +417,9 @@ class Time https://github.com/ruby/ruby/blob/trunk/lib/time.rb#L417
           force_zone!(t, zone)
         end
       else
-        if !d[:year] && !d[:mon] && !d[:mday] && !d[:hour] && !d[:min] && !d[:sec] && !d[:sec_fraction]
-          raise ArgumentError, "no time information in #{date.inspect}"
-        end
         year = d[:year]
         year = yield(year) if year && block_given?
-        t = make_time(year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
+        t = make_time(date, year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
       end
       t
     end

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

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