summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--lib/time.rb16
2 files changed, 12 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index bf292c9a2d..ae4da220d5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
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