mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* applied patch by MoonWolf <moonwolf@moonwolf.com> 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
This commit is contained in:
parent
0cf2581ec1
commit
8b38f8c03e
4 changed files with 54 additions and 20 deletions
|
@ -126,6 +126,10 @@ class DateTime
|
||||||
[@year, @month, @day, @hour, @min, @sec]
|
[@year, @month, @day, @hour, @min, @sec]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ==(o)
|
||||||
|
self.to_a == o.to_a
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -84,18 +84,32 @@ module XMLRPC
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.dateTime(str)
|
def self.dateTime(str)
|
||||||
if str =~ /^(-?\d\d\d\d)(\d\d)(\d\d)T(\d\d):(\d\d):(\d\d)$/ then
|
case str
|
||||||
# TODO: Time.gm ??? .local ???
|
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}
|
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)
|
XMLRPC::DateTime.new(*a)
|
||||||
#if a[0] >= 1970 then
|
|
||||||
# Time.gm(*a)
|
|
||||||
#else
|
|
||||||
# Date.new(*a[0,3])
|
|
||||||
#end
|
|
||||||
else
|
else
|
||||||
raise "wrong dateTime.iso8601 format"
|
raise "wrong dateTime.iso8601 format " + str
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
8
test/xmlrpc/data/datetime_iso8601.xml
Normal file
8
test/xmlrpc/data/datetime_iso8601.xml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<methodResponse>
|
||||||
|
<params>
|
||||||
|
<param>
|
||||||
|
<value><dateTime.iso8601>20041105T01:15:23Z</dateTime.iso8601></value>
|
||||||
|
</param>
|
||||||
|
</params>
|
||||||
|
</methodResponse>
|
|
@ -1,25 +1,29 @@
|
||||||
$LOAD_PATH.unshift '../../lib'
|
$LOAD_PATH.unshift '../../lib'
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
|
require 'xmlrpc/datetime'
|
||||||
require "xmlrpc/parser"
|
require "xmlrpc/parser"
|
||||||
|
|
||||||
module GenericParserTest
|
module GenericParserTest
|
||||||
def setup
|
def setup
|
||||||
@xml1 = File.readlines("data/xml1.xml").to_s
|
@xml1 = File.read("data/xml1.xml")
|
||||||
@expected1 = File.readlines("data/xml1.expected").to_s.chomp
|
@expected1 = File.read("data/xml1.expected").chomp
|
||||||
|
|
||||||
@xml2 = File.readlines("data/bug_covert.xml").to_s
|
@xml2 = File.read("data/bug_covert.xml")
|
||||||
@expected2 = File.readlines("data/bug_covert.expected").to_s.chomp
|
@expected2 = File.read("data/bug_covert.expected").chomp
|
||||||
|
|
||||||
@xml3 = File.readlines("data/bug_bool.xml").to_s
|
@xml3 = File.read("data/bug_bool.xml")
|
||||||
@expected3 = File.readlines("data/bug_bool.expected").to_s.chomp
|
@expected3 = File.read("data/bug_bool.expected").chomp
|
||||||
|
|
||||||
@xml4 = File.readlines("data/value.xml").to_s
|
@xml4 = File.read("data/value.xml")
|
||||||
@expected4 = File.readlines("data/value.expected").to_s.chomp
|
@expected4 = File.read("data/value.expected").chomp
|
||||||
|
|
||||||
@cdata_xml = File.readlines("data/bug_cdata.xml").to_s.chomp
|
@cdata_xml = File.read("data/bug_cdata.xml").chomp
|
||||||
@cdata_expected = File.readlines("data/bug_cdata.expected").to_s.chomp
|
@cdata_expected = File.read("data/bug_cdata.expected").chomp
|
||||||
|
|
||||||
@fault_doc = File.readlines("data/fault.xml").to_s
|
@datetime_xml = File.read("data/datetime_iso8601.xml")
|
||||||
|
@datetime_expected = XMLRPC::DateTime.new(2004, 11, 5, 1, 15, 23)
|
||||||
|
|
||||||
|
@fault_doc = File.read("data/fault.xml").to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
# test parseMethodResponse --------------------------------------------------
|
# test parseMethodResponse --------------------------------------------------
|
||||||
|
@ -40,6 +44,10 @@ module GenericParserTest
|
||||||
assert_equal(@cdata_expected, @p.parseMethodResponse(@cdata_xml).inspect)
|
assert_equal(@cdata_expected, @p.parseMethodResponse(@cdata_xml).inspect)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_dateTime
|
||||||
|
assert_equal(@datetime_expected, @p.parseMethodResponse(@datetime_xml)[1])
|
||||||
|
end
|
||||||
|
|
||||||
# test parseMethodCall ------------------------------------------------------
|
# test parseMethodCall ------------------------------------------------------
|
||||||
|
|
||||||
def test_parseMethodCall
|
def test_parseMethodCall
|
||||||
|
|
Loading…
Add table
Reference in a new issue