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

ruby-changes:10755

From: akr <ko1@a...>
Date: Sun, 15 Feb 2009 07:04:46 +0900 (JST)
Subject: [ruby-changes:10755] Ruby:r22318 (trunk): * lib/time.rb (Time.parse): raise ArgumentError if Date._parse don't

akr	2009-02-15 07:03:28 +0900 (Sun, 15 Feb 2009)

  New Revision: 22318

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

  Log:
    * lib/time.rb (Time.parse): raise ArgumentError if Date._parse don't
      extract date information.  [ruby-core:20912]

  Modified files:
    trunk/ChangeLog
    trunk/NEWS
    trunk/lib/time.rb
    trunk/test/test_time.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 22317)
+++ ChangeLog	(revision 22318)
@@ -1,3 +1,8 @@
+Sun Feb 15 06:34:22 2009  Tanaka Akira  <akr@f...>
+
+	* lib/time.rb (Time.parse): raise ArgumentError if Date._parse don't
+	  extract date information.  [ruby-core:20912]
+
 Sun Feb 15 04:48:08 2009  Yusuke Endoh  <mame@t...>
 
 	* string.c (rb_hash_uint32, rb_hash_uint, rb_hash_start, rb_hash_end),
Index: lib/time.rb
===================================================================
--- lib/time.rb	(revision 22317)
+++ lib/time.rb	(revision 22318)
@@ -214,9 +214,11 @@
     #
     #     # Suppose it is "Thu Nov 29 14:33:20 GMT 2001" now and
     #     # your timezone is GMT:
-    #     Time.parse("16:30")     #=> Thu Nov 29 16:30:00 GMT 2001
-    #     Time.parse("7/23")      #=> Mon Jul 23 00:00:00 GMT 2001
-    #     Time.parse("Aug 31")    #=> Fri Aug 31 00:00:00 GMT 2001
+    #     now = 
+    #     Time.parse("16:30")     #=> 2001-11-29 16:30:00 +0900
+    #     Time.parse("7/23")      #=> 2001-07-23 00:00:00 +0900
+    #     Time.parse("Aug 31")    #=> 2001-08-31 00:00:00 +0900
+    #     Time.parse("Aug 2000")  #=> 2000-08-01 00:00:00 +0900
     #
     # Since there are numerous conflicts among locally defined timezone
     # abbreviations all over the world, this method is not made to
@@ -252,6 +254,9 @@
     #
     def parse(date, now=self.now)
       d = Date._parse(date, false)
+      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?
       make_time(year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
Index: NEWS
===================================================================
--- NEWS	(revision 22317)
+++ NEWS	(revision 22318)
@@ -150,6 +150,10 @@
     * Readline.completion_proc= accepts nil.
       nil means to use default completion proc.
 
+* time
+  * incompatible changes:
+    * Time.parse raises ArgumentError when no date information.
+
 === Compatibility issues (excluding feature bug fixes)
 
   * Enumerator#rewind
Index: test/test_time.rb
===================================================================
--- test/test_time.rb	(revision 22317)
+++ test/test_time.rb	(revision 22318)
@@ -176,6 +176,7 @@
     #assert_equal(Time.local(2001,11,1), Time.parse("Nov", now))
     assert_equal(Time.local( 2001,11,29,10,22),
                  Time.parse(           "10:22", now))
+    assert_raise(ArgumentError) { Time.parse("foo", now) }
   end
 
   def test_invalid

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

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