diff --git a/src/app/modules/time-entries/pages/time-entries.component.spec.ts b/src/app/modules/time-entries/pages/time-entries.component.spec.ts index 77511dae6..08e785621 100644 --- a/src/app/modules/time-entries/pages/time-entries.component.spec.ts +++ b/src/app/modules/time-entries/pages/time-entries.component.spec.ts @@ -240,6 +240,27 @@ describe('TimeEntriesComponent', () => { entry: { project_id: 'p-id', start_date: '2020-05-05T10:04', + end_date: '2020-05-05T11:04', + description: 'description', + technologies: [], + uri: 'abc', + }, shouldRestartEntry: false + }; + component.entryId = 'new-entry'; + spyOn(injectedToastrService, 'error'); + + component.saveEntry(newEntry); + + expect(injectedToastrService.error).toHaveBeenCalled(); + }); + + it('displays an error when end date of entry is > than active entry start date', async () => { + component.activeTimeEntry = entry; + const newEntry = { + entry: { + project_id: 'p-id', + start_date: '2020-01-05T10:04', + end_date: '2020-03-05T11:04', description: 'description', technologies: [], uri: 'abc', diff --git a/src/app/modules/time-entries/pages/time-entries.component.ts b/src/app/modules/time-entries/pages/time-entries.component.ts index 01b929fc2..d62e3ec7e 100644 --- a/src/app/modules/time-entries/pages/time-entries.component.ts +++ b/src/app/modules/time-entries/pages/time-entries.component.ts @@ -101,11 +101,11 @@ export class TimeEntriesComponent implements OnInit, OnDestroy { saveEntry(event: SaveEntryEvent): void { if (this.activeTimeEntry !== null && this.activeTimeEntry !== undefined) { - const entryDateAsIso = new Date(event.entry.start_date).toISOString(); - const entryDateAsLocalDate = new Date(entryDateAsIso); + const startDateAsLocalDate = new Date(event.entry.start_date); + const endDateAsLocalDate = new Date(event.entry.end_date); const activeEntryAsLocalDate = new Date(this.activeTimeEntry.start_date); const isEditingActiveEntry = this.entryId === this.activeTimeEntry.id; - if (!isEditingActiveEntry && entryDateAsLocalDate > activeEntryAsLocalDate) { + if (!isEditingActiveEntry && (startDateAsLocalDate > activeEntryAsLocalDate || endDateAsLocalDate > activeEntryAsLocalDate)) { this.toastrService.error('You are on the clock and this entry overlaps it, try with earlier times.'); } else { this.doSave(event);