summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-05-03 18:11:53 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-05-03 18:11:53 +0000
commitaf56a2b6dc790170bc0876d09c0287832a14a5b7 (patch)
treea661744f96a7f33fbc2fc37173a56cca3767212c /lib
parentf5c91e5775929412f4b1bdb6f1de6f9ad305f14b (diff)
* lib/time.rb (Time.rfc2822): Fix year completion.
Produce fixed-offset time object if appropriate. (Time.xmlschema): Produce fixed-offset time object if appropriate. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45800 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/time.rb29
1 files changed, 17 insertions, 12 deletions
diff --git a/lib/time.rb b/lib/time.rb
index 507bf28daf..cb37c4e562 100644
--- a/lib/time.rb
+++ b/lib/time.rb
@@ -445,24 +445,26 @@ class Time
day = $1.to_i
mon = MonthValue[$2.upcase]
year = $3.to_i
+ short_year_p = $3.length <= 3
hour = $4.to_i
min = $5.to_i
sec = $6 ? $6.to_i : 0
zone = $7
- # following year completion is compliant with RFC 2822.
- year = if year < 50
- 2000 + year
- elsif year < 1000
- 1900 + year
- else
- year
- end
+ if short_year_p
+ # following year completion is compliant with RFC 2822.
+ year = if year < 50
+ 2000 + year
+ else
+ 1900 + year
+ end
+ end
+ off = zone_offset(zone)
year, mon, day, hour, min, sec =
- apply_offset(year, mon, day, hour, min, sec, zone_offset(zone))
+ apply_offset(year, mon, day, hour, min, sec, off)
t = self.utc(year, mon, day, hour, min, sec)
- t.localtime if !zone_utc?(zone)
+ t.localtime(off) if !zone_utc?(zone)
t
else
raise ArgumentError.new("not RFC 2822 compliant date: #{date.inspect}")
@@ -550,9 +552,12 @@ class Time
end
if $8
zone = $8
+ off = zone_offset(zone)
year, mon, day, hour, min, sec =
- apply_offset(year, mon, day, hour, min, sec, zone_offset(zone))
- self.utc(year, mon, day, hour, min, sec, usec)
+ apply_offset(year, mon, day, hour, min, sec, off)
+ t = self.utc(year, mon, day, hour, min, sec, usec)
+ t.localtime(off) if !zone_utc?(zone)
+ t
else
self.local(year, mon, day, hour, min, sec, usec)
end