Open jibees opened 3 years ago
- config.time_zone = ENV.fetch("TIMEZONE", "Melbourne")
+ config.time_zone = "UTC"
I think the Semaphore configs explicitly pass an ENV var for the timezone, and I guess the Github CI setup does not, but it wants UTC. I wonder if going half-way between those two options is the best? We could do:
config.time_zone = ENV.fetch("TIMEZONE", "UTC")
I think that will satisfy both...
Thanks @Matt-Yorkley In term of strictly green build, I think you are right and we should quickly follow your recommendations. But, to go further and regarding my investigations (I've updated the issue description), I think the issue is deeper than "just" timezone configuration into test env. And I've no idea on how to fix this.
Cool, I made a one-line PR for that change. Happy to leave this issue open though if you think it needs more investigation :+1:
Thanks @Matt-Yorkley ! Now I think this is issue is no more tech debt, and its priority should slightly decrease (and it seems that no one was bothered by this behaviour)
Where do you see we're converting the dates to UTC @jibees ? AFAIK we should send UTC dates to the backend and then localize them on the FE them depending on the user's timezone. Am I right?
I don't see anything that convert in UTC in the backend (actually I haven't looked for). In my explanations I've just converted to UTC to understand and compare date between each others. We send date with timezone to the server which can be a valid solution as it seems to be correctly understood (as we return the right orders)
then localize them on the FE them depending on the user's timezone. Am I right?
The date is formatted in the json, without taking into account the user's timezone.
What we should change and why
If server timezone is different from the client's browser one, orders may be returned when they should not be (and vice versa)
How to reproduce the bug?
You can change your timezone config test by editing
config/environments/test.rb
and change line 34 byconfig.time_zone = "UTC"
if you're not running you're browser in UTC. Therefore, tests inbulk_order_management_spec
line 466 and line 478 should fail.Output of the failing tests:
Order returned although should not be (
expected not to find visible css "tr#li_52", found 1 match
)2021-03-08
and query is sent to controller with paramcompleted_at_gteq
with value :2021-03-08T00:00:00+01:00
which is, converted in UTC:2021-03-07T23:00:00.000Z
.2021-03-07 23:59:59 UTC
is therefore returned by the controller.March 07, 2021
because the json contains the formatted string of the date, without taken into account the timezone of the user (seedef completed_at
inorder_serializer.rb
)Order not returned although should be (
expected to find css "tr#li_58" but there were no matches
)2021-03-15
and query is sent to controller with paramParamcompleted_at_lt
with value:2021-03-16T00:00:00+01:00
that is to say, in UTC:2021-03-15T23:00:00.000Z
2021-03-15 23:59:59 UTC
is not returned by controller.Old description (fixed by #7119, as we know use the same timezone in both server and client)
Tests in
bulk_order_management_spec.rb
fails since commit e341b044878792a64a8e39b1613434c4cee4b38aFile:
config/environments/test.rb
Context
PR: #6902 https://github.com/openfoodfoundation/openfoodnetwork/pull/6902/commits/5e19e5e83d88d741b1f49204892071ef3bfca28c