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

Parsing dates zeros out the year #107

Open
mattjohnsonpint opened this issue Jan 23, 2025 · 0 comments · Fixed by #108
Open

Parsing dates zeros out the year #107

mattjohnsonpint opened this issue Jan 23, 2025 · 0 comments · Fixed by #108

Comments

@mattjohnsonpint
Copy link
Contributor

mattjohnsonpint commented Jan 23, 2025

Not sure how I'm just now noticing this, but dates in JSON are strings, so they're quoted ie., "\"2024-12-31T23:59:59\""

... but when we deserialize dates, we are forgetting to strip off the quotes:

const d = Date.fromString(dateTimeString);

The effect is strange:

const d = JSON.parse<Date>('"2024-12-31T23:59:59"');
console.log(d.toISOString()); // 0000-12-31T23:59:59.123Z

The quotes somehow make Date.fromString skip the year component.

json-as version 0.9.28

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