aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-14 22:03:28 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-14 22:03:28 +0000
commit1b4c1f715e5abcf68ea680dbed3b36007b9aa761 (patch)
tree04b06c7b20d487695b36d862f69135a7849d332f
parente722ad99d5b0e6a9bb0249ff3d9c8cce28d3204e (diff)
downloadruby-1b4c1f715e5abcf68ea680dbed3b36007b9aa761.tar.gz
* lib/time.rb (Time.parse): raise ArgumentError if Date._parse don't
extract date information. [ruby-core:20912] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22318 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--NEWS4
-rw-r--r--lib/time.rb11
-rw-r--r--test/test_time.rb1
4 files changed, 18 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index da64174aad..1ed25423b1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sun Feb 15 06:34:22 2009 Tanaka Akira <akr@fsij.org>
+
+ * 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@tsg.ne.jp>
* string.c (rb_hash_uint32, rb_hash_uint, rb_hash_start, rb_hash_end),
diff --git a/NEWS b/NEWS
index 6b094e945c..9679feb0d9 100644
--- a/NEWS
+++ b/NEWS
@@ -150,6 +150,10 @@ with all sufficient information, see the ChangeLog file.
* 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
diff --git a/lib/time.rb b/lib/time.rb
index 29b8ca1f09..d1f6ba804b 100644
--- a/lib/time.rb
+++ b/lib/time.rb
@@ -214,9 +214,11 @@ class Time
#
# # 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 @@ class Time
#
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)
diff --git a/test/test_time.rb b/test/test_time.rb
index 0d53409e9b..844dc62314 100644
--- a/test/test_time.rb
+++ b/test/test_time.rb
@@ -176,6 +176,7 @@ class TestTimeExtention < Test::Unit::TestCase # :nodoc:
#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