2021-05-21 15:17:21 +02:00
|
|
|
const time = require('./time').default;
|
2020-08-08 01:13:21 +02:00
|
|
|
|
|
|
|
describe('timeUtils', function() {
|
|
|
|
|
2022-11-15 12:23:50 +02:00
|
|
|
|
2020-08-08 01:13:21 +02:00
|
|
|
|
2020-12-01 20:05:24 +02:00
|
|
|
it('should go back in time', (async () => {
|
2020-08-08 01:13:21 +02:00
|
|
|
let startDate = new Date('3 Aug 2020');
|
|
|
|
let endDate = new Date('2 Aug 2020');
|
|
|
|
|
|
|
|
expect(time.goBackInTime(startDate, 1, 'day')).toBe(endDate.getTime().toString());
|
|
|
|
|
|
|
|
// We're always subtracting time from the beginning of the current period.
|
2021-01-23 17:51:19 +02:00
|
|
|
startDate = new Date('3 Aug 2020 07:30:20');
|
2020-08-08 01:13:21 +02:00
|
|
|
expect(time.goBackInTime(startDate, 1, 'day')).toBe(endDate.getTime().toString());
|
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
// Note: this test randomly fails - https://github.com/laurent22/joplin/issues/3722
|
2020-08-08 01:13:21 +02:00
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
// startDate = new Date('11 Aug 2020');
|
|
|
|
// endDate = new Date('9 Aug 2020'); // week start;
|
|
|
|
// expect(time.goBackInTime(startDate, 0, 'week')).toBe(endDate.getTime().toString());
|
2020-08-08 01:13:21 +02:00
|
|
|
|
|
|
|
startDate = new Date('02 Feb 2020');
|
|
|
|
endDate = new Date('01 Jan 2020');
|
|
|
|
expect(time.goBackInTime(startDate, 1, 'month')).toBe(endDate.getTime().toString());
|
|
|
|
|
|
|
|
startDate = new Date('19 September 2020');
|
|
|
|
endDate = new Date('01 Jan 1997');
|
|
|
|
expect(time.goBackInTime(startDate, 23, 'year')).toBe(endDate.getTime().toString());
|
|
|
|
}));
|
|
|
|
|
2020-12-01 20:05:24 +02:00
|
|
|
it('should go forward in time', (async () => {
|
2020-08-08 01:13:21 +02:00
|
|
|
let startDate = new Date('2 Aug 2020');
|
|
|
|
let endDate = new Date('3 Aug 2020');
|
|
|
|
|
|
|
|
expect(time.goForwardInTime(startDate, 1, 'day')).toBe(endDate.getTime().toString());
|
|
|
|
|
2021-01-23 17:51:19 +02:00
|
|
|
startDate = new Date('2 Aug 2020 07:30:20');
|
2020-08-08 01:13:21 +02:00
|
|
|
expect(time.goForwardInTime(startDate, 1, 'day')).toBe(endDate.getTime().toString());
|
|
|
|
|
|
|
|
|
2020-09-22 17:02:22 +02:00
|
|
|
// startDate = new Date('9 Aug 2020');
|
|
|
|
// endDate = new Date('9 Aug 2020'); // week start;
|
|
|
|
// expect(time.goForwardInTime(startDate, 0, 'week')).toBe(endDate.getTime().toString());
|
2020-08-08 01:13:21 +02:00
|
|
|
|
|
|
|
startDate = new Date('02 Jan 2020');
|
|
|
|
endDate = new Date('01 Feb 2020');
|
|
|
|
expect(time.goForwardInTime(startDate, 1, 'month')).toBe(endDate.getTime().toString());
|
|
|
|
|
|
|
|
startDate = new Date('19 September 1997');
|
|
|
|
endDate = new Date('01 Jan 2020');
|
|
|
|
expect(time.goForwardInTime(startDate, 23, 'year')).toBe(endDate.getTime().toString());
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|