diff options
author | mneumann <mneumann@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-11-16 01:11:49 +0000 |
---|---|---|
committer | mneumann <mneumann@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-11-16 01:11:49 +0000 |
commit | 8b38f8c03e28f12c4c92a47a903558b55f350c9d (patch) | |
tree | 773c5aecefde9fe6e6aa8b8ee1d77a08062435e8 /lib/xmlrpc/parser.rb | |
parent | 0cf2581ec1ced929beaa04d154faaf8e41d0afeb (diff) |
* applied patch by MoonWolf <[email protected]> to allow parsing
datetime.iso8601 (e.g. 20041105T01:15:23Z).
* added test case
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7276 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/xmlrpc/parser.rb')
-rw-r--r-- | lib/xmlrpc/parser.rb | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/lib/xmlrpc/parser.rb b/lib/xmlrpc/parser.rb index ed0e9a66f3..db99bafafc 100644 --- a/lib/xmlrpc/parser.rb +++ b/lib/xmlrpc/parser.rb @@ -84,18 +84,32 @@ module XMLRPC end def self.dateTime(str) - if str =~ /^(-?\d\d\d\d)(\d\d)(\d\d)T(\d\d):(\d\d):(\d\d)$/ then - # TODO: Time.gm ??? .local ??? + case str + when /^(-?\d\d\d\d)-?(\d\d)-?(\d\d)T(\d\d):(\d\d):(\d\d)(?:Z|([+-])(\d\d):?(\d\d))?$/ + a = [$1, $2, $3, $4, $5, $6].collect{|i| i.to_i} + if $7 + ofs = $8.to_i*3600 + $9.to_i*60 + ofs = -ofs if $7=='+' + utc = Time.utc(a.reverse) + ofs + a = [ utc.year, utc.month, utc.day, utc.hour, utc.min, utc.sec ] + end + XMLRPC::DateTime.new(*a) + when /^(-?\d\d)-?(\d\d)-?(\d\d)T(\d\d):(\d\d):(\d\d)(Z|([+-]\d\d):(\d\d))?$/ a = [$1, $2, $3, $4, $5, $6].collect{|i| i.to_i} - + if a[0] < 70 + a[0] += 2000 + else + a[0] += 1900 + end + if $7 + ofs = $8.to_i*3600 + $9.to_i*60 + ofs = -ofs if $7=='+' + utc = Time.utc(a.reverse) + ofs + a = [ utc.year, utc.month, utc.day, utc.hour, utc.min, utc.sec ] + end XMLRPC::DateTime.new(*a) - #if a[0] >= 1970 then - # Time.gm(*a) - #else - # Date.new(*a[0,3]) - #end else - raise "wrong dateTime.iso8601 format" + raise "wrong dateTime.iso8601 format " + str end end |