-
-
Notifications
You must be signed in to change notification settings - Fork 467
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(maintenance): timezone handling offset issue #981
fix(maintenance): timezone handling offset issue #981
Conversation
(just a heads-up - fairly new to golang, so let me know if there's any more go-typical ways of handling things) |
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.
Excellent catch! Just a small nitpick with the newlines, but looks perfect otherwise!
config/maintenance/maintenance.go
Outdated
|
||
adjustedDate := now.Day() | ||
if now.Hour() < int(c.durationToStartFromMidnight.Hours()) { | ||
// if time in maintenance window is later than now, treat it as yesterday | ||
adjustedDate-- | ||
} | ||
// Set to midnight prior to adding duration | ||
dayWhereMaintenancePeriodWouldStart = time.Date(now.Year(), now.Month(), adjustedDate, 0, 0, 0, 0, now.Location()) | ||
|
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.
Can you remove the blank lines?
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.
Done 👍
I also just realised I can remove the separate variable definition for |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #981 +/- ##
=======================================
Coverage 75.86% 75.86%
=======================================
Files 74 74
Lines 6758 6758
=======================================
Hits 5127 5127
Misses 1325 1325
Partials 306 306 ☔ View full report in Codecov by Sentry. |
@alexmaras Thank you for the contribution! |
Summary
Fixes an issue with the timezone handling in Maintenance blocks
#911
The problem was with using Truncate, which always operates in UTC. Switching to constructing the date from component parts (
0, 0, 0, 0
for midnight) fixes this issue and makes the time always midnight for the timezone the maintenance window refers to.I've added a test for this too - the previous test didn't catch the problem because it was only an hour out from UTC, and the window covered a 2 hour period. I've using UTC+8 (Australia/Perth) for a large enough gap to catch the issue. This test fails without the code changes, and passes now.
Checklist
README.md
, if applicable. (Not applicable - bugfixing existing behavior)