-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
fix: ISO date parsing #10011
fix: ISO date parsing #10011
Conversation
b6e84ec
to
eec1989
Compare
src/util/DateUtils.ts
Outdated
console.log( | ||
"isIsoDataTime", | ||
isDateTime, | ||
isoDateString, | ||
parsed, | ||
parsed.toISOString(), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log( | |
"isIsoDataTime", | |
isDateTime, | |
isoDateString, | |
parsed, | |
parsed.toISOString(), | |
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, how did I not catch that? ^^
src/util/DateUtils.ts
Outdated
|
||
const isDateTime = isoDateString.includes("T") | ||
if (!isDateTime) { | ||
// This lets the date parser now that the date is to be treat as local time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// This lets the date parser now that the date is to be treat as local time. | |
// This lets the date parser know that the date is to be treat as local time. |
eec1989
to
c02b0b6
Compare
Not a maintainer of the repo so can't help with getting this merged, but really looking forward to the fix for the issue this is targetting (as it is affecting me as well). |
c02b0b6
to
07347ef
Compare
thanks @felix-gohla for taking a look on this one. Tests are failing however... |
I appreciate your response. I have refrained from fixing them until now because there are some discussion parts (see PR description). 😊 If you say that typeorm should handle all the cases itself (without external library), then I can continue and fix the tests. |
Add a test for date handling functions that seem to ignore the timezone offsets on insert. Related to typeorm#9941 Introduced in typeorm#9634
Add handling for the different timezones during parsing ISO dates as there's a difference in date parsing and date-times parsing in the ECMA-script specs. Fix the bit where even dates with given timezones were parsed as local time. Related To typeorm#9941
07347ef
to
81a8d8a
Compare
Closed by 54f4f89 |
Description of change
Fix date parsing ignoring time zones.
In the code there's a explanation with link to the ECMA-script specification on why that happens.
The error was introduced when removing
date-fns
from typeorm in #9634.Discussion
However: I wonder if it is even intended to deviate from the standard (even if the distinction between date and date-times seems a little bit... odd). Currently, the parse function always assumes local time unless there's a timezone given. This could be confusing.
During testing I also noticed that there are some tests that relied on another date format.
Maybe it would be wise to decide which date standard to go for (RFC3339 or ISO8601, see this website for comparison).
Furthermore, not sure if it makes sense to handle this by code in typeorm itself.
There are other people who really already invested time into figuring dates out in JS.
Fixes #9941
Pull-Request Checklist
master
branchnpm run format
to apply prettier formattingnpm run test
passes with this changeFixes #0000