Make start date and day of month aware of timezones (fixes #12555) (#12696)

* WIP: #12555

-dayOfMonth takes timezone into account on task update for monthly dailys
-startDate set to start of day in user's tz on task update for monthly
dailys
-tweaked a test so that it's actually testing something

* WIP: 12555

-task.startDate gets set to start of day in user's tz on task creation
and task update
-set preferences.timezoneOffset to nonzero value in certian test user objects
-removed date literals in test:api-v3:integration:tasks:PUT
This commit is contained in:
bakerty
2021-01-10 07:02:40 -08:00
committed by GitHub
parent e8d3090a99
commit db3d233ae5
8 changed files with 83 additions and 29 deletions

View File

@@ -678,18 +678,29 @@ api.updateTask = {
task.group.managerNotes = sanitizedObj.managerNotes;
}
// If the daily task was set to repeat monthly on a day of the month, and the start date was
// updated, the task will then need to be updated to repeat on the same day of the month as the
// new start date. For example, if the start date is updated to 7/2/2020, the daily should
// repeat on the 2nd day of the month. It's possible that a task can repeat monthly on a
// week of the month, in which case we won't update the repetition at all.
if (
task.type === 'daily'
&& task.frequency === 'monthly'
&& task.daysOfMonth.length
&& task.startDate
// For daily tasks, update start date based on timezone to maintain consistency
if (task.type === 'daily'
&& task.startDate
) {
task.daysOfMonth = [moment(task.startDate).date()];
task.startDate = moment(task.startDate).utcOffset(
-user.preferences.timezoneOffset,
).startOf('day').toDate();
// If the daily task was set to repeat monthly on a day of the month, and the start date was
// updated, the task will then need to be updated to repeat on the same day of the month as
// the new start date. For example, if the start date is updated to 7/2/2020, the daily
// should repeat on the 2nd day of the month. It's possible that a task can repeat monthly
// on a week of the month, in which case we won't update the repetition at all.
if (
task.frequency === 'monthly'
&& task.daysOfMonth.length
) {
// We also need to aware of the user's timezone. Start date is represented as UTC, so the
// start date and day of month might be different
task.daysOfMonth = [moment(task.startDate).utcOffset(
-user.preferences.timezoneOffset,
).date()];
}
}
setNextDue(task, user);