Repository navigation
fix(api): correct UTC offset label for negative half-hour timezones - #10079
Abhishek-B-R wants to merge 1 commit into
Conversation
The hours were taken with floor division on a negative number of seconds, so -34200 // 3600 gave -10 and Marquesas showed as UTC-10:30 instead of UTC-09:30. Newfoundland was off by an hour the same way. Take the sign first and split the absolute value instead.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
|
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
Description
The timezone picker gets its "UTC-xx:xx" labels from
GET /api/timezones/, and every zone that is west of UTC with a half-hour offset comes back one hour too far west.The label is built like this:
Python floors negative division, so for Marquesas (-34200 seconds)
hours_offsetis -10 and the minutes come out as 30, givingUTC-10:30. The real offset isUTC-09:30. Positive zones like Kolkata (+05:30) and Kathmandu (+05:45) are fine, which is probably why nobody noticed.What the endpoint returns today vs what it should:
So anyone in Newfoundland picking their timezone sees a label an hour off, and searching the picker for "GMT-02:30" finds nothing.
The fix takes the sign first and splits the absolute value with
divmod, so the hours and minutes are always computed on a positive number. Thestrftime("%z")value used for sorting is untouched.Type of Change
Test Scenarios
Added
apps/api/plane/tests/unit/views/test_timezone_endpoint.py. It calls the endpoint withdatetime.now()pinned to a January and a July date (so the Newfoundland DST case is covered) and a locmem cache, and checks bothutc_offsetandgmt_offsetfor Marquesas, St Johns, Kolkata, Kathmandu, Los Angeles and Reykjavik.Before the fix, 3 of the 7 cases fail (the three rows in the table above). After the fix all 7 pass.
ruff checkandruff format --checkare clean on both files.References
No existing issue. Found by reading the offset formatting while checking how half-hour zones (I'm in IST) are handled.
Summary by CodeRabbit