summaryrefslogtreecommitdiff
path: root/lib/time.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-07-24 07:47:01 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-07-24 07:47:01 +0000
commit728b75bc9bba6786d36dbc19f3c05f26322d0946 (patch)
tree14a3c7e716cf23c8398327361e31a1f8e78ca799 /lib/time.rb
parent727f6ee8efdd02019294076f7f41338eb8b8277a (diff)
time.rb: yday support
* lib/time.rb (Time.make_time): added yday support. [ruby-core:87545] [Bug #14860] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64028 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/time.rb')
-rw-r--r--lib/time.rb19
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/time.rb b/lib/time.rb
index e227166c47..0d740b25b0 100644
--- a/lib/time.rb
+++ b/lib/time.rb
@@ -245,8 +245,8 @@ class Time
end
private :apply_offset
- def make_time(date, year, mon, day, hour, min, sec, sec_fraction, zone, now)
- if !year && !mon && !day && !hour && !min && !sec && !sec_fraction
+ def make_time(date, year, yday, mon, day, hour, min, sec, sec_fraction, zone, now)
+ if !year && !yday && !mon && !day && !hour && !min && !sec && !sec_fraction
raise ArgumentError, "no time information in #{date.inspect}"
end
@@ -256,6 +256,17 @@ class Time
off = zone_offset(zone, off_year) if zone
end
+ if yday
+ mon, day = (yday-1).divmod(31)
+ mon += 1
+ day += 1
+ t = make_time(date, year, nil, mon, day, hour, min, sec, sec_fraction, zone, now)
+ diff = yday - t.yday
+ return t if diff.zero?
+ day += diff
+ return make_time(date, year, nil, mon, day, hour, min, sec, sec_fraction, zone, now)
+ end
+
if now
if off
now = now.getlocal(off) if now.utc_offset != off
@@ -363,7 +374,7 @@ class Time
d = Date._parse(date, comp)
year = d[:year]
year = yield(year) if year && !comp
- make_time(date, year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
+ make_time(date, year, d[:yday], d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
end
#
@@ -441,7 +452,7 @@ class Time
else
year = d[:year]
year = yield(year) if year && block_given?
- t = make_time(date, year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
+ t = make_time(date, year, d[:yday], d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
end
t
end