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

Handle DateOnly in typescript client as local date (not UTC) #1480

Closed
Shaddix opened this issue Jan 15, 2022 · 2 comments · Fixed by #1481
Closed

Handle DateOnly in typescript client as local date (not UTC) #1480

Shaddix opened this issue Jan 15, 2022 · 2 comments · Fixed by #1481

Comments

@Shaddix
Copy link
Contributor

Shaddix commented Jan 15, 2022

DateOnly is serialized to JSON as 'yyyy-MM-dd' (e.g. '2022-01-16').
When it's deserialized (in JS), NJsonSchema uses new Date('2022-01-16').
Considering I'm in New York (UTC -5), new Date('2022-01-16').toLocaleString() gives me 1/15/2022, 7:00:00 PM, and new Date('2022-01-16').toLocaleDateString() gives 1/15/2022.
Moreover, if I now send this received DateOnly back to my API, it'd be sent as 2022-01-15, because formatDate (used in NJsonSchema for DateOnly serialization) uses local date.

My personal expectation was to get it deserialized as 1/16/2022, 12:00:00 AM (regardless of my time zone).

I understand, that JS by default interprets 'yyyy-MM-dd' as UTC date, but imo it'd be correct to adjust DateOnly fields after deserialization (or at least to make it configurable/provide some callbacks that I could set to adjust deserialization for DateOnly fields)

@Shaddix
Copy link
Contributor Author

Shaddix commented Jan 15, 2022

btw, Luxon, Moment, DayJs interpret '2022-01-16' in local timezone, so only native js dates are affected (i.e. TypeScriptDateTimeType.Date)

@Shaddix
Copy link
Contributor Author

Shaddix commented Jan 15, 2022

I could PR that if you are ok with the idea and could help me with name for setting (in TypeScriptGeneratorSettings), that will enable that behavior :)

RicoSuter pushed a commit that referenced this issue Sep 16, 2022
* Convert DateOnly properties to local timezone for TypeScriptDateTimeType.Date

* adjust parseDateOnly

* fix ArrayItemDate

* fix DateOnly code
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

Successfully merging a pull request may close this issue.

1 participant