#1 2025-01-12 20:50:12

ertank
Member
Registered: 2016-03-16
Posts: 175

UnixTime de-serialization

Hello,

I am using Delphi 12.2, mORMot from GitHub January 3, 2025 update.

Is it possible to have mORMot2 de-serialize to auto convert Unix Time (with/without milliseconds) Int64 values to TDateTime?

uses
  System.DateUtils, mormot.core.json, mormot.core.base;

type
  TTest = packed record
    ADate: TDateTime;
  end;

procedure TForm1.FormCreate(Sender: TObject);
const cTest = '{"adate":1736705403567}';  // with milliseconds
var LRec: TTest;
begin
  mormot.core.json.RecordLoadJson(LRec, RawUtf8(cTest), TypeInfo(TTest));
  ShowMessage(LRec.ADate.ToString());
end;

Above code cause an overflow (if turned on)

Thanks & Regards,
Ertan

Offline

#2 2025-01-13 08:33:36

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

Re: UnixTime de-serialization

Offline

#3 2025-01-13 11:57:07

ertank
Member
Registered: 2016-03-16
Posts: 175

Re: UnixTime de-serialization

That's working.
Thank you.

Offline

Board footer

Powered by FluxBB