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
timezone is ignored with parseJSON #2149
Comments
@DaSchTour |
@tan75 GMT+0100 |
@DaSchTour |
I have a suggestion. Instead of create a Date.UTC with each part of the string we can use the default API to parse it. Like below: return new Date(argument); Below follow the whole parseJSON function. export default function parseJSON(argument) {
requiredArgs(1, arguments)
if (typeof argument === 'string') {
var parts = argument.match(
/(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2}):(\d{2})(?:\.(\d{0,7}))?(?:Z|\+00:?00)?/
)
if (parts) {
return new Date(
Date.UTC(
+parts[1],
parts[2] - 1,
+parts[3],
+parts[4],
+parts[5],
+parts[6],
+((parts[7] || '0') + '00').substring(0, 3)
)
)
}
return new Date(NaN)
}
return toDate(argument)
} |
@tan75 I've made some tests locally and the proposal converts correctly. If you agree, I can do the change. |
hi @alarangeiras Thanks a lot for the suggestion. Let me investigate this issue a bit. |
Hi @tan75, you're welcome... let me know if i can help you with the fix. |
Hi Allan, after doing some digging, it was discovered that the issue was in the Regex that was matching the dates - it supported only zero offsets. I fixed it in one of my PRs and hopefully it will be approved and released soon. |
I made this small test https://runkit.com/daschtour/parsejson-timezone and found that when using parseJSON on a date string with timezone it get's lost in the conversion. So for my case using one date converting it to JSON and converting it back to a date adds one hour, although the timezone offset is added back correctly.
The text was updated successfully, but these errors were encountered: