-
Notifications
You must be signed in to change notification settings - Fork 297
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
Update shift week_start when translating to UTC #2124
Conversation
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.
In the same way that we render the shift start / end datetimes (returned as UTC by the backend) in the selected TZ, I think we should map by_day
selected days accordingly, as mentioned here.
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.
LGTM 👍
export const getUTCWeekStart = (dayOptions: SelectOption[], moment: dayjs.Dayjs) => { | ||
let week_start_index = 0; | ||
let byDayOptions = []; | ||
dayOptions.forEach(({ value }) => byDayOptions.push(value)); | ||
if (moment.day() !== moment.utc().day()) { | ||
// when converting to UTC, shift starts on a different day, | ||
// so we may need to change when week starts based on the UTC start time | ||
// depending on the UTC side, move one day before or after | ||
let offset = moment.utcOffset(); | ||
if (offset < 0) { | ||
// move one day after | ||
week_start_index = (week_start_index + 1) % 7; | ||
} else { | ||
// move one day before | ||
week_start_index = (((week_start_index - 1) % 7) + 7) % 7; | ||
} | ||
} | ||
return byDayOptions[week_start_index]; | ||
}; | ||
|
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.
nit consider adding a unit test here
1bc8ae5
to
8658b6e
Compare
This fixes scenario described [here](#2118 (comment)). When a rotation is setup in UTC+1, and the shift starts at 00:00 with Monday as active day and a weekly frequency, the values are translated to UTC when submitting to the backend, so the shift data becomes something like: shift starting at 23:00 on Sunday, but since week_start is on Monday, the "first event" in the week belongs to the "previous week". This can be addressed by moving the week_start, so a weekly shift that was starting on a Monday but in UTC tz starts on Sunday, "translates" to a UTC week_start on Sunday: ![rotation-example](https://github.com/grafana/oncall/assets/260710/5222d3ce-52b7-41d5-8ecb-d01c7a0139cb) (this is with the proposed changes; otherwise you get the same issue linked above where the first event in the week is assigned to the other user group). About selected week days changed when editing a rotation, see inline comment (related to [this](#1322 (comment)))
This fixes scenario described here.
When a rotation is setup in UTC+1, and the shift starts at 00:00 with Monday as active day and a weekly frequency, the values are translated to UTC when submitting to the backend, so the shift data becomes something like: shift starting at 23:00 on Sunday, but since week_start is on Monday, the "first event" in the week belongs to the "previous week". This can be addressed by moving the week_start, so a weekly shift that was starting on a Monday but in UTC tz starts on Sunday, "translates" to a UTC week_start on Sunday:
(this is with the proposed changes; otherwise you get the same issue linked above where the first event in the week is assigned to the other user group).
About selected week days changed when editing a rotation, see inline comment (related to this)