diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-23 10:48:54 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-23 10:48:54 +0000 |
commit | 6b5a2b2f06a72bf67081040c263dadf485601ee8 (patch) | |
tree | 02a1fd2794754175c3960cd71a4747fd43cf14bb | |
parent | 5d592124f5700a762fc9a153031c786bb739f58d (diff) |
* lib/time.rb (Time.httpdate): fix 2 digits year for 20xx.
reported by Tadayoshi Funaba. [ruby-dev:32687]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14522 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | lib/time.rb | 11 |
2 files changed, 15 insertions, 1 deletions
@@ -1,3 +1,8 @@ +Sun Dec 23 19:45:22 2007 Tanaka Akira <akr@fsij.org> + + * lib/time.rb (Time.httpdate): fix 2 digits year for 20xx. + reported by Tadayoshi Funaba. [ruby-dev:32687] + Sun Dec 23 19:33:42 2007 Eric Hodel <drbrain@segment7.net> * lib/open-uri.rb: Fix method redefined warning. [ruby-core:14304] diff --git a/lib/time.rb b/lib/time.rb index 0cd9008521..201f2fee39 100644 --- a/lib/time.rb +++ b/lib/time.rb @@ -338,7 +338,13 @@ class Time (\d\d):(\d\d):(\d\d)\x20 GMT \s*\z/ix =~ date - Time.utc(1900+$3.to_i, $2, $1.to_i, $4.to_i, $5.to_i, $6.to_i) + year = $3.to_i + if year < 50 + year += 2000 + else + year += 1900 + end + Time.utc(year, $2, $1.to_i, $4.to_i, $5.to_i, $6.to_i) elsif /\A\s* (?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)\x20 (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\x20 @@ -543,6 +549,9 @@ if __FILE__ == $0 Time.httpdate("Tue, 15 Nov 1994 12:45:26 GMT")) assert_equal(Time.utc(1999, 12, 31, 23, 59, 59), Time.httpdate("Fri, 31 Dec 1999 23:59:59 GMT")) + + assert_equal(Time.utc(2007, 12, 23, 11, 22, 33), + Time.httpdate('Sunday, 23-Dec-07 11:22:33 GMT')) end def test_rfc3339 |