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

Fixes #1480. Convert DateOnly properties to local timezone #1481

Merged
merged 6 commits into from
Sep 16, 2022

Conversation

Shaddix
Copy link
Contributor

@Shaddix Shaddix commented Jan 16, 2022

Fixes #1480

@RicoSuter
Copy link
Owner

If this PR should still be merged, please fix the conflicts and we'll have a look at it.

# Conflicts:
#	src/NJsonSchema.CodeGeneration.TypeScript/TypeScriptGeneratorSettings.cs
@Shaddix
Copy link
Contributor Author

Shaddix commented May 16, 2022

conflicts are fixed

@RicoSuter RicoSuter merged commit d76549a into RicoSuter:master Sep 16, 2022
@RicoSuter
Copy link
Owner

Thanks for the PR.

@wuzzeb
Copy link

wuzzeb commented Sep 21, 2023

I think this PR doesn't completely fix the issue of dates and timezones, because serialization always assumes a local timezone.

Thus, if the setting ConvertDateToLocalTimezone is false, the parsing code will use new Date("2023-09-21") which assumes UTC but the formatting code calls formatDate (https://github.com/RicoSuter/NJsonSchema/blob/master/src/NJsonSchema.CodeGeneration.TypeScript/Templates/File.FormatDate.liquid) which uses d.getMonth() etc which assume local timezone.

This means if ConvertDateToLocalTimezone is false, you can parse and then immediately convert back to JSON and get a different result.

There should also be a formatUTCDate function which uses instead getUTCMonth and friends, because dates are assumed to be in UTC.

Then, when ConvertDateToLocalTimezone is false, the generated toJSON function should use formtUTCDate instead of formatDate.

Then, both the serialization and deserialization will both use the same expected format and you can serialize followed by a deserialize without changing the data.

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

Successfully merging this pull request may close these issues.

Handle DateOnly in typescript client as local date (not UTC)
3 participants