mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/time.rb (Time.strptime): use Time.at if d[:seconds] is set.
Reported by Christopher Eberz. [ruby-core:39903] Bug #5399 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33398 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
bf8168cf33
commit
4eb497d90b
3 changed files with 13 additions and 3 deletions
|
@ -1,3 +1,8 @@
|
|||
Tue Oct 4 16:17:50 2011 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* lib/time.rb (Time.strptime): use Time.at if d[:seconds] is set.
|
||||
Reported by Christopher Eberz. [ruby-core:39903] Bug #5399
|
||||
|
||||
Tue Oct 4 15:04:43 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* class.c (class_alloc): allocate extra memory after containing
|
||||
|
|
10
lib/time.rb
10
lib/time.rb
|
@ -280,9 +280,13 @@ class Time
|
|||
def strptime(date, format, now=self.now)
|
||||
d = Date._strptime(date, format)
|
||||
raise ArgumentError, "invalid strptime format - `#{format}'" unless d
|
||||
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)
|
||||
if seconds = d[:seconds]
|
||||
Time.at(seconds)
|
||||
else
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
||||
MonthValue = {
|
||||
|
|
|
@ -392,6 +392,7 @@ class TestTimeExtension < Test::Unit::TestCase # :nodoc:
|
|||
|
||||
def test_strptime
|
||||
assert_equal(Time.utc(2005, 8, 28, 06, 54, 20), Time.strptime("28/Aug/2005:06:54:20 +0000", "%d/%b/%Y:%T %z"))
|
||||
assert_equal(Time.at(1).localtime, Time.strptime("1", "%s"))
|
||||
end
|
||||
|
||||
def test_nsec
|
||||
|
|
Loading…
Reference in a new issue