fix(news-widget): enforce strict UTC date parsing to prevent timezone…#1366
Conversation
88fb795 to
15640f7
Compare
|
Hello @regulartim Can you check my pr please ! |
regulartim
left a comment
There was a problem hiding this comment.
Hey @suvani-ctrl ! Your fix is correct and well implemented, as far as I can see. Good work! :)
An explicit regression test that forces a non-UTC TZ (like via process.env.TZ = "America/Los_Angeles") would be a good addition. This test should deterministically fail without your fix but pass when the fix is in place.
15640f7 to
b9e831f
Compare
|
Hello @regulartim I updated the production code and added the regression test based on your feedback. The fix now forces the news widget to use explicit UTC parsing (getUTCDate() and timeZone: "UTC").. so everyone sees the exact same threat intel dates regardless of their location. For the regression test, I temporarily mocked the timezone inside the code using process.env.TZ = "America/Los_Angeles" and also cleaned it up in a finally block. I also avoided putting this timezon in a global .env file because changing the timezone globally would break other tests. I verified locally that this new test fails without my fix and passes when the fix is there. All 16 tests seems to pass on mine with my fixes and fail without those fixes. I have attached screenshots for better understandings . Please let me know if this is okay or not. ---> Test Failing before utc updates
|


Description
This PR fixes a bug where the NewsWidget displays the wrong date for users in Western timezones (for example, showing "31st Dec 2023" instead of "2024-01-01").
The app was using the user's local computer time to read a UTC date string. The bug was fixed by forcing the code to use UTC everywhere (
getUTCDate()andtimeZone: "UTC"). Now, everyone sees the exact same correct date no matter where they live.Related issues
Closes #1362
Type of change
Checklist
Please complete this checklist carefully. It helps guide your contribution and lets maintainers verify that all requirements are met.
Formalities
<feature name>. Closes #999develop.develop.Docs and tests
Ruff) gave 0 errors. If you have correctly installed pre-commit, it does these checks and adjustments on your behalf.GUI changes
Ignore this section if you did not make any changes to the GUI.
Review process