Skip to content

JSONRPC incorrectly decodes UTC values for DateTime Params #560

@fastbike

Description

@fastbike

We have a JSONRPC method with this signature
function EndPractitionerRole(ID: Int64; LastUpdated: TDateTime): Boolean;

We send data
{"jsonrpc":"2.0","id":926270,"method":"EndPractitionerRole","params":{"ID":1203521835,"LastUpdated":"2022-06-10T09:08:25+12:00"}}

As our current local UTC offset is +12 hours, we are expecting to see a local datetime in the method's parameter of 9:08:25 am on 10 June 2022

Instead we see a local datetime of 9:08:25 pm on 09 June 2022 which is 12 hours earlier i.e. it misses the offset.

NB: We also see the same behaviour if the JSON contains a zulu coded value i.e. 2022-06-09T21:08:25Z

This is caused by the mapping performed by JSONDataValueToTValueParam

The code in the following snippet will never call the code in the else part because by definition all UTC date times must contain "T"

    else if SameText(RTTIParameter.ParamType.Name, 'TDateTime') then
        begin
          if JSONDataValue.Value.Contains('T') then // always evaluates to TRUE
            JSONRPCRequestParams.Add(JSONDataValue.UtcDateTimeValue, pdtDateTime)
          else // never called with an UTC timestamp
            JSONRPCRequestParams.Add(ISOTimeStampToDateTime(JSONDataValue.Value), pdtDateTime);
        end

And the code in the underlying JsonDataObjects has a hard coded False for the "useLocalTime" param in the call to return UtcDateTimeValue

In the debugger if I jump into the else part so the ISOTimeStampToDateTime method is called then the correct value appears in the JSONRPC method's parameter.

Metadata

Metadata

Labels

acceptedIssue has been accepted and inserted in a future milestone

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions