mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/time.rb (Time.make_time): Argument validation code moved from
Time.parse and Time.strptime. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45841 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d03eabd520
commit
915ef9ed9b
2 changed files with 12 additions and 9 deletions
|
@ -1,3 +1,8 @@
|
|||
Tue May 6 18:03:05 2014 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* lib/time.rb (Time.make_time): Argument validation code moved from
|
||||
Time.parse and Time.strptime.
|
||||
|
||||
Tue May 6 17:27:06 2014 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* lib/time.rb (Time.parse): [DOC] Fix an example in the documentation
|
||||
|
|
16
lib/time.rb
16
lib/time.rb
|
@ -246,7 +246,11 @@ class Time
|
|||
end
|
||||
private :apply_offset
|
||||
|
||||
def make_time(year, mon, day, hour, min, sec, sec_fraction, zone, now)
|
||||
def make_time(date, year, mon, day, hour, min, sec, sec_fraction, zone, now)
|
||||
if !year && !mon && !day && !hour && !min && !sec && !sec_fraction
|
||||
raise ArgumentError, "no time information in #{date.inspect}"
|
||||
end
|
||||
|
||||
usec = nil
|
||||
usec = sec_fraction * 1000000 if sec_fraction
|
||||
if now
|
||||
|
@ -341,12 +345,9 @@ class Time
|
|||
def parse(date, now=self.now)
|
||||
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]
|
||||
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)
|
||||
make_time(date, year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
|
||||
end
|
||||
|
||||
#
|
||||
|
@ -416,12 +417,9 @@ class Time
|
|||
force_zone!(t, zone)
|
||||
end
|
||||
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 = 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(date, year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
|
||||
end
|
||||
t
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue