diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-05-06 09:04:09 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-05-06 09:04:09 +0000 |
commit | 915ef9ed9b6222e2b890641051a21e77de64fb16 (patch) | |
tree | 48bcce4ec1d679ccf482446772b11efc858c47ec /lib/time.rb | |
parent | d03eabd52010b25e7a53c832792338ebe6ce2ead (diff) | |
download | ruby-915ef9ed9b6222e2b890641051a21e77de64fb16.tar.gz |
* 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
Diffstat (limited to 'lib/time.rb')
-rw-r--r-- | lib/time.rb | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/lib/time.rb b/lib/time.rb index edb1452d52..31a93f932f 100644 --- a/lib/time.rb +++ b/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 |