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

Understanding "DefaultMARSJSONSerializationOptions.DateIsUTC" #118

Open
ertankucukoglu opened this issue Jan 30, 2022 · 3 comments
Open
Assignees

Comments

@ertankucukoglu
Copy link

Hello,

By the meaning of subject variable, I understand that TDateTime values will be converted to UTC when it is set to True. Such as 2022-01-30T00:00:00.000Z value from database where server is set to UTC+3 will be converted to 2022-01-29T21:00:00.000Z

If that understanding is correct, I confirm that there is a bug and it works the other way around in the latest commit.
If that understanding is wrong, then give it to my misunderstanding and sorry for the noise.

Currently, when this variable is set to True values in json string are same as in database, when set to False values are converted to UTC.

I appreciate some clarification, please.

Thanks & Regards,
Ertan

@andrea-magni
Copy link
Owner

Hi @ertankucukoglu , I have to say I am a bit unsure here.
The DateIsUTC value of the DefaultMARSSerializationOptions is passed through a number of function calls.
At the very end of my reasonings, I would say it means "the current server date time is always UTC" so no time zone conversions are made (neither serializing nor de-serializing to and from JSON).

You can spot the time zone specified in the serialized string value (Z = UTC):

// with DateIsUTC = True on my machine (that is on Rome time zone: +02:00 at the moment)
"dateTime": "2023-05-11T10:13:49.055Z"

// with DateIsUTC = False on my machine (that is on Rome time zone: +02:00 at the moment)
"dateTime": "2023-05-11T12:22:50.717+02:00",

In the first case (DateIsUTC = True) the value is actually converted to UTC (my clock was showing 12:13:49 because I am in Rome time zone +1 with another +1 of daylight saving).

I have mixed feeling about the name "DateIsUTC". Is it misleading?

Thank you, regards

@andrea-magni
Copy link
Owner

Probably one of the issues is that it is not so usual to have a machine with UTC time.
What about adding a dynamic initialization for the DateIsUTC option?

  ( uses System.DateUtils )

    var LUTCOffsetInMinutes := Trunc(TTimeZone.Local.GetUTCOffset(Now).TotalMinutes);
    DefaultMARSJSONSerializationOptions.DateIsUTC := LUTCOffsetInMinutes = 0;

If your server is in UTC timezone (no offset with UTC), the value would be set to True. False otherwise (my local machine would be False then and I would have date time values serialized with explicit timezone offsets).

andrea-magni added a commit that referenced this issue May 11, 2023
DefaultMARSJSONSerializationOptions.DateIsUTC now gets initialized in the initialization section of MARS.Core.JSON unit.
@ertankucukoglu
Copy link
Author

Thank you for explanation.
Likely that fix will work fine.

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

No branches or pull requests

2 participants