1
0
Fork 0
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:
akr 2014-05-06 09:04:09 +00:00
parent d03eabd520
commit 915ef9ed9b
2 changed files with 12 additions and 9 deletions

View file

@ -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> Tue May 6 17:27:06 2014 Tanaka Akira <akr@fsij.org>
* lib/time.rb (Time.parse): [DOC] Fix an example in the documentation * lib/time.rb (Time.parse): [DOC] Fix an example in the documentation

View file

@ -246,7 +246,11 @@ class Time
end end
private :apply_offset 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 = nil
usec = sec_fraction * 1000000 if sec_fraction usec = sec_fraction * 1000000 if sec_fraction
if now if now
@ -341,12 +345,9 @@ class Time
def parse(date, now=self.now) def parse(date, now=self.now)
comp = !block_given? comp = !block_given?
d = Date._parse(date, comp) 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 = d[:year]
year = yield(year) if year && !comp 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 end
# #
@ -416,12 +417,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(date, year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
end end
t t
end end