Skip to content

Bug with serializing&deserializing of TDateTime values #8

Description

@vfisher

Wrong serializing&deserializing of TDateTime values, when local timezone <> 0. In the sample project datetime converts twice from UTC to local and we have wrong value of TDateTime field in the end.

"SuperRttiContextDefault.SuperDateTimeZoneHandling:= sdzLOCAL" has no effect.

program sobug2;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  superobject;
Var
  s: String = '{"DocTime":"2024-05-24T21:52:11"}';

Type
  TSomeTime = Class
    DocTime: TDateTime;
  End;

var
  obj: TSomeTime;
  ACTX: TSuperRttiContext;
begin
  try
    ACTX:= TSuperRttiContext.Create;
    try
      obj:= ACTX.AsType<TSomeTime>(SO(s));
      WriteLn('old: ' + s);
      s:= ACTX.AsJson<TSomeTime>(obj).AsJson(False, False);
      WriteLn('new: ' + s);
    finally
      ACTX.Free;
    end;

  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions