Skip to content

Commit 015fa55

Browse files
authored
Merge pull request #836 from nextcloud/fix/todo-timeframe-check
fix: time frame check of vtodos
2 parents cb072cf + 8f900ce commit 015fa55

2 files changed

Lines changed: 102 additions & 4 deletions

File tree

src/components/root/toDoComponent.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,22 @@ export default class ToDoComponent extends AbstractRecurringComponent {
145145
* @return {boolean}
146146
*/
147147
isInTimeFrame(start, end) {
148-
if (!this.hasProperty('dtstart') && !this.hasProperty('due')) {
148+
const startDate = this.startDate
149+
const endDate = this.endDate
150+
151+
if (!startDate && !endDate) {
149152
return true
150153
}
151154

152-
if (!this.hasProperty('dtstart') && this.hasProperty('due')) {
153-
return start.compare(this.endDate) <= 0
155+
if (startDate && !endDate) {
156+
return end.compare(startDate) >= 0
157+
}
158+
159+
if (!startDate && endDate) {
160+
return start.compare(endDate) <= 0
154161
}
155162

156-
return start.compare(this.endDate) <= 0 && end.compare(this.startDate) >= 0
163+
return start.compare(endDate) <= 0 && end.compare(startDate) >= 0
157164
}
158165

159166
/**

tests/unit/components/root/todoComponent.test.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,3 +364,94 @@ it('ToDoComponent should provide access methods for CONFERENCE', () => {
364364
expect(component.getConferenceList().length).toEqual(0)
365365
expect(component.getConferenceList()).toEqual([])
366366
})
367+
368+
it.each([
369+
[
370+
'none',
371+
undefined,
372+
undefined,
373+
undefined,
374+
true,
375+
true,
376+
true,
377+
true,
378+
],
379+
[
380+
'DTSTART only',
381+
DateTimeValue.fromJSDate(new Date('2025-01-01T10:30:00Z')),
382+
undefined,
383+
undefined,
384+
false,
385+
true,
386+
true,
387+
true,
388+
],
389+
[
390+
'DTSTART and DUE',
391+
DateTimeValue.fromJSDate(new Date('2025-01-01T10:30:00Z')),
392+
undefined,
393+
DateTimeValue.fromJSDate(new Date('2025-01-01T10:50:00Z')),
394+
false,
395+
true,
396+
false,
397+
false,
398+
],
399+
[
400+
'DTSTART and DUE (overlapping)',
401+
DateTimeValue.fromJSDate(new Date('2025-01-01T10:30:00Z')),
402+
undefined,
403+
DateTimeValue.fromJSDate(new Date('2025-01-01T11:50:00Z')),
404+
false,
405+
true,
406+
true,
407+
false,
408+
],
409+
[
410+
'DTSTART and DURATION',
411+
DateTimeValue.fromJSDate(new Date('2025-01-01T10:30:00Z')),
412+
DurationValue.fromSeconds(900),
413+
undefined,
414+
false,
415+
true,
416+
false,
417+
false,
418+
],
419+
[
420+
'DTSTART and DURATION (overlapping)',
421+
DateTimeValue.fromJSDate(new Date('2025-01-01T10:30:00Z')),
422+
DurationValue.fromSeconds(3600),
423+
undefined,
424+
false,
425+
true,
426+
true,
427+
false,
428+
],
429+
])('ToDoComponent should report being inside a time frame - %s', (name, dtstart, duration, due, expectInTimeFrame1, expectInTimeFrame2, expectInTimeFrame3, expectInTimeFrame4) => {
430+
const component = new ToDoComponent('VTODO')
431+
432+
if (dtstart) {
433+
component.addProperty(new Property('dtstart', dtstart))
434+
}
435+
if (duration) {
436+
component.addProperty(new Property('duration', duration))
437+
}
438+
if (due) {
439+
component.addProperty(new Property('due', due))
440+
}
441+
442+
const date1 = DateTimeValue.fromJSDate(new Date('2025-01-01T09:00:00Z'))
443+
const date2 = DateTimeValue.fromJSDate(new Date('2025-01-01T09:59:59Z'))
444+
expect(component.isInTimeFrame(date1, date2)).toEqual(expectInTimeFrame1)
445+
446+
const date3 = DateTimeValue.fromJSDate(new Date('2025-01-01T10:00:00Z'))
447+
const date4 = DateTimeValue.fromJSDate(new Date('2025-01-01T10:59:59Z'))
448+
expect(component.isInTimeFrame(date3, date4)).toEqual(expectInTimeFrame2)
449+
450+
const date5 = DateTimeValue.fromJSDate(new Date('2025-01-01T11:00:00Z'))
451+
const date6 = DateTimeValue.fromJSDate(new Date('2025-01-01T11:59:59Z'))
452+
expect(component.isInTimeFrame(date5, date6)).toEqual(expectInTimeFrame3)
453+
454+
const date7 = DateTimeValue.fromJSDate(new Date('2025-01-01T12:00:00Z'))
455+
const date8 = DateTimeValue.fromJSDate(new Date('2025-01-01T13:00:00Z'))
456+
expect(component.isInTimeFrame(date7, date8)).toEqual(expectInTimeFrame4)
457+
})

0 commit comments

Comments
 (0)