mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/time.rb (Time.strptime): Raise ArgumentError if Date._strptime
doesn't extract date information. Reported by tadayoshi funaba. [ruby-core:62349] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45823 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a72f9f3476
commit
c2a87a1fa1
4 changed files with 15 additions and 0 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Mon May 5 11:44:03 2014 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* lib/time.rb (Time.strptime): Raise ArgumentError if Date._strptime
|
||||||
|
doesn't extract date information.
|
||||||
|
Reported by tadayoshi funaba. [ruby-core:62349]
|
||||||
|
|
||||||
Mon May 5 01:12:27 2014 Tadayoshi Funaba <tadf@dotrb.org>
|
Mon May 5 01:12:27 2014 Tadayoshi Funaba <tadf@dotrb.org>
|
||||||
|
|
||||||
* ext/date/date_core.c (rt_rewrite_frags): a new feature (not a
|
* ext/date/date_core.c (rt_rewrite_frags): a new feature (not a
|
||||||
|
|
1
NEWS
1
NEWS
|
@ -77,6 +77,7 @@ with all sufficient information, see the ChangeLog file.
|
||||||
fixed-offset Time objects.
|
fixed-offset Time objects.
|
||||||
It is happen when usual localtime doesn't preserve the offset from UTC.
|
It is happen when usual localtime doesn't preserve the offset from UTC.
|
||||||
* Time.httpdate produces always UTC Time object.
|
* Time.httpdate produces always UTC Time object.
|
||||||
|
* Time.strptime raises ArgumentError when no date information.
|
||||||
|
|
||||||
=== Built-in global variables compatibility issues
|
=== Built-in global variables compatibility issues
|
||||||
|
|
||||||
|
|
|
@ -416,6 +416,9 @@ class Time
|
||||||
force_zone!(t, zone)
|
force_zone!(t, zone)
|
||||||
end
|
end
|
||||||
else
|
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 = d[:year]
|
||||||
year = yield(year) if year && block_given?
|
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(year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
|
||||||
|
|
|
@ -423,6 +423,11 @@ class TestTimeExtension < Test::Unit::TestCase # :nodoc:
|
||||||
assert_equal(false, Time.strptime('0', '%s').utc?)
|
assert_equal(false, Time.strptime('0', '%s').utc?)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_strptime_empty
|
||||||
|
assert_raise(ArgumentError) { Time.strptime('', '') }
|
||||||
|
assert_raise(ArgumentError) { Time.strptime('+09:00', '%z') }
|
||||||
|
end
|
||||||
|
|
||||||
def test_strptime_s_z
|
def test_strptime_s_z
|
||||||
t = Time.strptime('0 +0100', '%s %z')
|
t = Time.strptime('0 +0100', '%s %z')
|
||||||
assert_equal(0, t.to_r)
|
assert_equal(0, t.to_r)
|
||||||
|
|
Loading…
Reference in a new issue