Skip to content
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

Merged
merged 1 commit into from
Jun 13, 2023

Conversation

matiasb
Copy link
Contributor

@matiasb matiasb commented Jun 7, 2023

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:

rotation-example

(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)

@matiasb matiasb added pr:no changelog pr:no public docs Added to a PR that does not require public documentation updates labels Jun 7, 2023
Copy link
Contributor Author

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.

Copy link
Contributor

@joeyorlando joeyorlando left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Comment on lines +55 to +74
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];
};

Copy link
Contributor

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

@matiasb matiasb force-pushed the matiasb/by-day-week-start-tz branch from 1bc8ae5 to 8658b6e Compare June 13, 2023 14:14
@matiasb matiasb marked this pull request as ready for review June 13, 2023 14:29
@matiasb matiasb requested review from a team June 13, 2023 14:29
@matiasb matiasb added this pull request to the merge queue Jun 13, 2023
Merged via the queue into dev with commit 6e5d417 Jun 13, 2023
@matiasb matiasb deleted the matiasb/by-day-week-start-tz branch June 13, 2023 14:36
brojd pushed a commit that referenced this pull request Sep 18, 2024
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)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:no public docs Added to a PR that does not require public documentation updates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants