Commit ca5d0503 authored by Justin Wood's avatar Justin Wood

Bug 533330: JSON-RPC webservice returns and expects a bad date format

r+a=mkanat
parent f4d7c9c1
...@@ -27,8 +27,7 @@ use base qw(JSON::RPC::Server::CGI Bugzilla::WebService::Server); ...@@ -27,8 +27,7 @@ use base qw(JSON::RPC::Server::CGI Bugzilla::WebService::Server);
use Bugzilla::Error; use Bugzilla::Error;
use Bugzilla::WebService::Constants; use Bugzilla::WebService::Constants;
use Bugzilla::WebService::Util qw(taint_data); use Bugzilla::WebService::Util qw(taint_data);
use Date::Parse; use Bugzilla::Util qw(datetime_from);
use DateTime;
sub new { sub new {
my $class = shift; my $class = shift;
...@@ -69,16 +68,23 @@ sub type { ...@@ -69,16 +68,23 @@ sub type {
$retval = "$value"; $retval = "$value";
} }
elsif ($type eq 'dateTime') { elsif ($type eq 'dateTime') {
# str2time uses Time::Local internally, so I believe it should # ISO-8601 "YYYYMMDDTHH:MM:SS" with a literal T
# always return seconds based on the *Unix* epoch, even if the $retval = $self->datetime_format($value);
# system doesn't use the Unix epoch.
$retval = str2time($value) * 1000;
} }
# XXX Will have to implement base64 if Bugzilla starts using it. # XXX Will have to implement base64 if Bugzilla starts using it.
return $retval; return $retval;
} }
sub datetime_format {
my ($self, $date_string) = @_;
# YUI expects ISO8601 in UTC time; uncluding TZ specifier
my $time = datetime_from($date_string, 'UTC');
my $iso_datetime = $time->iso8601() . 'Z';
return $iso_datetime;
}
################## ##################
# Login Handling # # Login Handling #
################## ##################
...@@ -162,9 +168,10 @@ sub _argument_type_check { ...@@ -162,9 +168,10 @@ sub _argument_type_check {
sub _bz_convert_datetime { sub _bz_convert_datetime {
my ($self, $time) = @_; my ($self, $time) = @_;
my $dt = DateTime->from_epoch(epoch => ($time / 1000),
time_zone => Bugzilla->local_timezone); my $converted = datetime_from($time, Bugzilla->local_timezone);
return $dt->strftime('%Y-%m-%d %T'); $time = $converted->ymd() . ' ' . $converted->hms();
return $time
} }
sub handle_login { sub handle_login {
...@@ -232,9 +239,16 @@ your JSON-RPC call would look like: ...@@ -232,9 +239,16 @@ your JSON-RPC call would look like:
For JSON-RPC 1.1, you can pass parameters either in the above fashion For JSON-RPC 1.1, you can pass parameters either in the above fashion
or using the standard named-parameters mechanism of JSON-RPC 1.1. or using the standard named-parameters mechanism of JSON-RPC 1.1.
C<dateTime> fields are represented as an integer number of microseconds C<dateTime> fields are strings in the standard ISO-8601 format:
since the Unix epoch (January 1, 1970 UTC). They are always in the UTC C<YYYY-MM-DDTHH:MM:SSZ>, where C<T> and C<Z> are a literal T and Z,
timezone. respectively. The "Z" means that all times are in UTC timezone--times are
always returned in UTC, and should be passed in as UTC. (Note: The JSON-RPC
interface currently also accepts non-UTC times for any values passed in, if
they include a time-zone specifier that follows the ISO-8601 standard, instead
of "Z" at the end. This behavior is expected to continue into the future, but
to be fully safe for forward-compatibility with all future versions of
Bugzilla, it is safest to pass in all times as UTC with the "Z" timezone
specifier.)
All other types are standard JSON types. All other types are standard JSON types.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment