-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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 date field being parsed with a timezone #10033
Conversation
Codecov Report
@@ Coverage Diff @@
## master #10033 +/- ##
=======================================
Coverage 60.06% 60.06%
=======================================
Files 183 183
Lines 5702 5702
Branches 1077 1077
=======================================
Hits 3425 3425
Misses 1817 1817
Partials 460 460
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
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.
why isn't it necesssary on the other types like datetime ?
Seems like the test are breaking now
Honestly I have no idea, it's extremely difficult for me to track down how or why the local system timezone is being pulled in. The backend should -only- function in UTC. The Admin panel should be doing the time conversion but the date field specifically is the only field that shouldn't even be working with time but the default JS |
That is the issue @petersg83 is we are using parsing functions which is converting it to a datetime (with TZ information). Realistically we shouldn't be parsing the date other than maybe to change formats (US uses What we need is for the frontend to only send UTC/GMT and parse it on the server like that without reading the system timezone, but we also need to customize this in case some users for whatever reason change the database timezone (which can be done on SQL databases) |
Signed-off-by: Derrick Mehaffy <derrickmehaffy@gmail.com>
This reverts commit 498180477bf1750aa177a27786cc9b4e873c4e95.
@soupette I only changed the input data, not the filter. I think it's good enough for the moment, I don't have time to dig if there is a problem with how we handle the dates with the filter |
Signed-off-by: Derrick Mehaffy derrickmehaffy@gmail.com
What does it do?
Stops using the built in Javascript date which reads the systems timezone by replacing
new Date()
with the date-fns functionparseISO
see it's docs hereWhy is it needed?
if the string value passed from upstream in Strapi is
2021-04-14
:date-fns function
javascript native function
The problem is that the built in Javascript
Date()
will use the local systems timezone, and instead the date-fns has the ability to just parse the raw date string and not pass in the system timezone.How to test it?
Your system must be set to a timezone that is +/- GMT by at least 1 hour
Related issue(s)/PR(s)
fixes #9576
[Edit]
I (@petersg83 ) took over this PR. It appears the problem is quite complex and larger than this specific issue. We need to refactor all the way we handle dates (disable timezone in pg for instance) and it would be more of a breaking change than a bug fix. So we won't fix everything now but it will be fixed in V4 (should come in beta ~summer and released before the end of the year).
However, I wrote a small change in the admin. It may fix #9576, not sure.