From e787398f714fa33ef12ad4b5da79624b7435c8db Mon Sep 17 00:00:00 2001 From: "Randy J. Ray" Date: Fri, 21 Jan 2011 20:48:50 -0800 Subject: [PATCH] RT#62916: Fixed dateTime.iso8601 stringification. --- lib/RPC/XML.pm | 6 +++--- t/10_data.t | 8 +++++++- t/20_xml_parser.t | 2 +- t/21_xml_libxml.t | 24 ++++++++++++------------ 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/lib/RPC/XML.pm b/lib/RPC/XML.pm index 06ec392..5e4a8f9 100644 --- a/lib/RPC/XML.pm +++ b/lib/RPC/XML.pm @@ -61,7 +61,7 @@ BEGIN RPC_DATETIME_ISO8601 RPC_BASE64 RPC_NIL) ], all => [ @EXPORT_OK ]); -$VERSION = '1.51'; +$VERSION = '1.52'; $VERSION = eval $VERSION; ## no critic (ProhibitStringyEval) # Global error string @@ -125,7 +125,7 @@ sub time2iso8601 my $zone = shift || q{}; my @time = gmtime $time; - $time = sprintf '%4d-%02d-%02dT%02d:%02d:%02dZ', + $time = sprintf '%4d%02d%02dT%02d:%02d:%02dZ', $time[5] + 1900, $time[4] + 1, @time[3, 2, 1, 0]; if ($zone) { @@ -570,7 +570,7 @@ sub new # given in the spec, so assume that other implementations can only # accept this form. Also, this should match the form that time2iso8601 # produces. - $value = $7 ? "$1-$2-$3T$4:$5:$6$7" : "$1-$2-$3T$4:$5:$6"; + $value = $7 ? "$1$2$3T$4:$5:$6$7" : "$1$2$3T$4:$5:$6"; if ($8) { $value .= $8; diff --git a/t/10_data.t b/t/10_data.t index b50512c..4362127 100644 --- a/t/10_data.t +++ b/t/10_data.t @@ -5,7 +5,7 @@ use strict; use vars qw($val $obj $class %val_tbl @values); -use Test::More tests => 198; +use Test::More tests => 200; use RPC::XML ':all'; # First, the most basic data-types @@ -121,6 +121,12 @@ $obj = RPC::XML::datetime_iso8601->new(); ok(! ref $obj, "RPC::XML::datetime_iso8601, bad value did not yield referent"); like($RPC::XML::ERROR, qr/::new: Malformed data.*passed/, 'RPC::XML::datetime_iso8601, bad value correctly set \$RPC::XML::ERROR'); +# Test the slightly different date format +$obj = RPC::XML::datetime_iso8601->new('2008-09-29T12:00:00-07:00'); +is($obj->type, 'dateTime.iso8601', + "RPC::XML::datetime_iso8601, type identification"); +is($obj->value, '20080929T12:00:00-07:00', + 'RPC::XML::datetime_iso8601, value() method test'); # Test the base64 type require MIME::Base64; diff --git a/t/20_xml_parser.t b/t/20_xml_parser.t index de99475..4284091 100644 --- a/t/20_xml_parser.t +++ b/t/20_xml_parser.t @@ -81,7 +81,7 @@ SKIP: { ok($args->[5]->value, 'RPC::XML::boolean value parsed OK'); isa_ok($args->[6], 'RPC::XML::datetime_iso8601', 'Parse of argument'); - is($args->[6]->value, '2008-09-29T12:00:00-07:00', + is($args->[6]->value, '20080929T12:00:00-07:00', 'RPC::XML::dateTime.iso8601 value parsed OK'); isa_ok($args->[7], 'RPC::XML::array', 'Parse of argument'); is(scalar(@{$args->[7]->value}), 2, 'RPC::XML::array value parsed OK'); diff --git a/t/21_xml_libxml.t b/t/21_xml_libxml.t index f84ab45..76bb420 100644 --- a/t/21_xml_libxml.t +++ b/t/21_xml_libxml.t @@ -7,17 +7,17 @@ use vars qw($p $req $res $ret $dir $vol $file); BEGIN { - use Test::More; - - eval "use XML::LibXML"; - if ($@) - { - plan skip_all => "XML::LibXML not installed"; - } - else - { - plan tests => 40; - } + use Test::More; + + eval "use XML::LibXML"; + if ($@) + { + plan skip_all => "XML::LibXML not installed"; + } + else + { + plan tests => 40; + } } require File::Spec; @@ -95,7 +95,7 @@ SKIP: { ok($args->[5]->value, 'RPC::XML::boolean value parsed OK'); isa_ok($args->[6], 'RPC::XML::datetime_iso8601', 'Parse of argument'); - is($args->[6]->value, '2008-09-29T12:00:00-07:00', + is($args->[6]->value, '20080929T12:00:00-07:00', 'RPC::XML::dateTime.iso8601 value parsed OK'); isa_ok($args->[7], 'RPC::XML::array', 'Parse of argument'); is(scalar(@{$args->[7]->value}), 2, 'RPC::XML::array value parsed OK');