#1 2016-04-14 15:46:14

esmondb
Member
From: London
Registered: 2010-07-20
Posts: 299

RecordLoadJSON and TTimeLog

I can't get RecordLoadJSON to work with records containing TTimeLog.
But it seems to work if TTimeLog is defined as int64 (using delphi 2007).
I've put an example program below.

program test;

{$APPTYPE CONSOLE}

uses
  SysUtils, SynCommons;

type
  myJSON = packed record
    myDate: TTimeLog;
    s: string; //added to create some TypeInfo
  end;

const
  __myJSON = 'myDate:TTimeLog; s:string';
  testString = '{"myDate":135305815903}';

var
  myRecord: myJSON;

begin
  TTextWriter.RegisterCustomJSONSerializerFromText(TypeInfo(myJSON),__myJSON);
  RecordLoadJSON(myRecord,testString,TypeInfo(myJSON));

  writeln(DateToStr(TimeLogToDateTime(myRecord.myDate))); //outputs 12/30/1899
         //if myDate is defined as an Int64 then output is correct - 4/14/2016

  writeln(DateToStr(TimeLogToDateTime(135305815903)));     //outputs 4/14/2016

  readln;

end.

Is this a bug?

Offline

#2 2016-04-14 16:05:01

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: RecordLoadJSON and TTimeLog

There was indeed a problem.
In text-based serialization, TTimeLog was serialized as ISO-8601 text, whereas it should have been serialized as plain Int64.
Just like with TJSONSerializer (i.e. class serialization).

Should be fixed by http://synopse.info/fossil/info/6e2fdf56bd

Thanks for the feedback!

Offline

#3 2016-04-14 16:31:37

esmondb
Member
From: London
Registered: 2010-07-20
Posts: 299

Re: RecordLoadJSON and TTimeLog

Thanks smile

Offline

Board footer

Powered by FluxBB