Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TDateTime in SO(...) paremeters #153

Open
EgorovAlex opened this issue Jan 13, 2024 · 3 comments
Open

TDateTime in SO(...) paremeters #153

EgorovAlex opened this issue Jan 13, 2024 · 3 comments

Comments

@EgorovAlex
Copy link

Hello,

Is it impossible to create Json TDateTime field with SO paremeter?

var X := SO(['Date', Now]);
var sJson := X.AsJSON; // Here we have Double value for 'Date' in Json

var X := SO;
X.D['Date'] := Now;
var sJson := X.AsJSON; // Here we have DateTime value, as expected

@vkrapotkin
Copy link
Contributor

The JSON itself doesn't specify the format of date/time, so these fields are stored just as string (or integer or FP-number)
Actual format is choosed by a programmer.
The back conversion is not obvious by the same reason.
But you can inherit class TJsonObject and add cusom property D or whatever else.

@EgorovAlex
Copy link
Author

EgorovAlex commented Jan 13, 2024

No, this example demostrate 2 method's of initialization for one library and result must be identical!
Or (if is it impossible) all restrictions must be described.

var S: string := 'Str';
var D: TDateTime := Now;
var I: Integer := 123;
var F: Double := 12.12;
var sJson1 := SO(['S', S, 'D', D, 'I', I, 'F', F]).AsJSON;
var X := SO;
X.S['S'] := S;
X.D['D'] := D;
X.I['I'] := I;
X.F['F'] := F;
var sJson2 := X.AsJSON;

sJson1 = '{"S":"Str","D":45304.7648217708,"I":123,"F":12.12}'
sJson2 = '{"S":"Str","D":"2024-01-13T18:21:20.601","I":123,"F":12.12}'

@EgorovAlex
Copy link
Author

This can be fixed with using another declaration:
function SO(... array of TValue)
with TValue is it possible to determine TDateTime type,
but possible to reduce supported versions of Delphi (and possible Lazarus)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants