From 9a9405da0b6b5baf8157206d34ba3895fb33b788 Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Thu, 4 Mar 2010 14:28:32 -0500 Subject: Bug 545299, XML-RPC WebService should take and return dates and times in UTC. Code part, r+=mkanat --- Bugzilla/WebService.pm | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'Bugzilla/WebService.pm') diff --git a/Bugzilla/WebService.pm b/Bugzilla/WebService.pm index 21c6b8175..3db28142e 100644 --- a/Bugzilla/WebService.pm +++ b/Bugzilla/WebService.pm @@ -21,6 +21,8 @@ package Bugzilla::WebService; use strict; use Date::Parse; use XMLRPC::Lite; +use Bugzilla::Util qw(datetime_from); +use Scalar::Util qw(blessed) # Used by the JSON-RPC server to convert incoming date fields apprpriately. use constant DATE_FIELDS => {}; @@ -36,21 +38,24 @@ sub login_exempt { sub type { my ($self, $type, $value) = @_; if ($type eq 'dateTime') { - $value = datetime_format($value); + $value = $self->datetime_format_outbound($value); } return XMLRPC::Data->type($type)->value($value); } -sub datetime_format { - my ($date_string) = @_; - - my $time = str2time($date_string); - my ($sec, $min, $hour, $mday, $mon, $year) = localtime $time; - # This format string was stolen from SOAP::Utils->format_datetime, - # which doesn't work but which has almost the right format string. - my $iso_datetime = sprintf('%d%02d%02dT%02d:%02d:%02d', - $year + 1900, $mon + 1, $mday, $hour, $min, $sec); - return $iso_datetime; +sub datetime_format_outbound { + my ($self, $date) = @_; + + my $time = $date; + if (blessed($date)) { + # We expect this to mean we were sent a datetime object + $time->set_time_zone('UTC'); + } else { + # We always send our time in UTC, for consistency. + # passed in value is likely a string, create a datetime object + $time = datetime_from($date, 'UTC'); + } + return $iso_datetime = $time->iso8601(); } -- cgit v1.2.3-24-g4f1b