mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/time.rb (Time.parse): use year completion in Date._parse.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23258 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f50bcf9317
commit
258ed42c12
2 changed files with 7 additions and 16 deletions
|
@ -1,3 +1,7 @@
|
|||
Wed Apr 22 19:33:13 2009 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* lib/time.rb (Time.parse): use year completion in Date._parse.
|
||||
|
||||
Wed Apr 22 11:12:15 2009 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||
|
||||
* time.c (GMTIME, LOCALTIME): should set result if not have *_r().
|
||||
|
|
19
lib/time.rb
19
lib/time.rb
|
@ -253,26 +253,13 @@ class Time
|
|||
# A failure for Time.parse should be checked, though.
|
||||
#
|
||||
def parse(date, now=self.now)
|
||||
d = Date._parse(date, false)
|
||||
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]
|
||||
if year
|
||||
if block_given?
|
||||
year = yield(year)
|
||||
else
|
||||
year = if year < 0
|
||||
year
|
||||
elsif year < 50
|
||||
2000 + year
|
||||
elsif year < 100
|
||||
1900 + year
|
||||
else
|
||||
year
|
||||
end
|
||||
end
|
||||
end
|
||||
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)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue