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

@@ -10,9 +10,14 @@ import {
describe('PUT /tasks/:id', () => {
let user;
let tzoffset;
before(async () => {
tzoffset = (new Date()).getTimezoneOffset();
});
beforeEach(async () => {
user = await generateUser();
user = await generateUser({ 'preferences.timezoneOffset': tzoffset });
});
context('validates params', () => {
@@ -503,7 +508,8 @@ describe('PUT /tasks/:id', () => {
let monthly;
beforeEach(async () => {
const date1 = moment.utc('2020-07-01').toDate();
// using date literals is discouraged here, daylight savings will break everything
const date1 = moment().toDate();
monthly = await user.post('/tasks/user', {
text: 'test monthly',
type: 'daily',
@@ -514,7 +520,7 @@ describe('PUT /tasks/:id', () => {
});
it('updates days of month when start date updated', async () => {
const date2 = moment.utc('2020-07-01').toDate();
const date2 = moment().add(6, 'months').toDate();
const savedMonthly = await user.put(`/tasks/${monthly._id}`, {
startDate: date2,
});
@@ -523,18 +529,30 @@ describe('PUT /tasks/:id', () => {
});
it('updates next due when start date updated', async () => {
const date2 = moment.utc('2022-07-01').toDate();
const date2 = moment().add(6, 'months').toDate();
const savedMonthly = await user.put(`/tasks/${monthly._id}`, {
startDate: date2,
});
expect(savedMonthly.nextDue.length).to.eql(6);
expect(moment(savedMonthly.nextDue[0]).toDate()).to.eql(moment.utc('2022-08-01').toDate());
expect(moment(savedMonthly.nextDue[1]).toDate()).to.eql(moment.utc('2022-09-01').toDate());
expect(moment(savedMonthly.nextDue[2]).toDate()).to.eql(moment.utc('2022-10-01').toDate());
expect(moment(savedMonthly.nextDue[3]).toDate()).to.eql(moment.utc('2022-11-01').toDate());
expect(moment(savedMonthly.nextDue[4]).toDate()).to.eql(moment.utc('2022-12-01').toDate());
expect(moment(savedMonthly.nextDue[5]).toDate()).to.eql(moment.utc('2023-01-01').toDate());
expect(moment(savedMonthly.nextDue[0]).toDate()).to.eql(
moment(date2).add(1, 'months').startOf('day').toDate(),
);
expect(moment(savedMonthly.nextDue[1]).toDate()).to.eql(
moment(date2).add(2, 'months').startOf('day').toDate(),
);
expect(moment(savedMonthly.nextDue[2]).toDate()).to.eql(
moment(date2).add(3, 'months').startOf('day').toDate(),
);
expect(moment(savedMonthly.nextDue[3]).toDate()).to.eql(
moment(date2).add(4, 'months').startOf('day').toDate(),
);
expect(moment(savedMonthly.nextDue[4]).toDate()).to.eql(
moment(date2).add(5, 'months').startOf('day').toDate(),
);
expect(moment(savedMonthly.nextDue[5]).toDate()).to.eql(
moment(date2).add(6, 'months').startOf('day').toDate(),
);
});
});