Skip to content

Commit 2e9ab62

Browse files
author
Guido Quezada
committed
TT-69 fix: adding or editing an entry must not overlap the date of an active entry
1 parent 4844725 commit 2e9ab62

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/app/modules/time-entries/pages/time-entries.component.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,27 @@ describe('TimeEntriesComponent', () => {
240240
entry: {
241241
project_id: 'p-id',
242242
start_date: '2020-05-05T10:04',
243+
end_date: '2020-05-05T11:04',
244+
description: 'description',
245+
technologies: [],
246+
uri: 'abc',
247+
}, shouldRestartEntry: false
248+
};
249+
component.entryId = 'new-entry';
250+
spyOn(injectedToastrService, 'error');
251+
252+
component.saveEntry(newEntry);
253+
254+
expect(injectedToastrService.error).toHaveBeenCalled();
255+
});
256+
257+
it('displays an error when end date of entry is > than active entry start date', async () => {
258+
component.activeTimeEntry = entry;
259+
const newEntry = {
260+
entry: {
261+
project_id: 'p-id',
262+
start_date: '2020-01-05T10:04',
263+
end_date: '2020-03-05T11:04',
243264
description: 'description',
244265
technologies: [],
245266
uri: 'abc',

src/app/modules/time-entries/pages/time-entries.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
101101

102102
saveEntry(event: SaveEntryEvent): void {
103103
if (this.activeTimeEntry !== null && this.activeTimeEntry !== undefined) {
104-
const entryDateAsIso = new Date(event.entry.start_date).toISOString();
105-
const entryDateAsLocalDate = new Date(entryDateAsIso);
104+
const startDateAsLocalDate = new Date(event.entry.start_date);
105+
const endDateAsLocalDate = new Date(event.entry.end_date);
106106
const activeEntryAsLocalDate = new Date(this.activeTimeEntry.start_date);
107107
const isEditingActiveEntry = this.entryId === this.activeTimeEntry.id;
108-
if (!isEditingActiveEntry && entryDateAsLocalDate > activeEntryAsLocalDate) {
108+
if (!isEditingActiveEntry && (startDateAsLocalDate > activeEntryAsLocalDate || endDateAsLocalDate > activeEntryAsLocalDate)) {
109109
this.toastrService.error('You are on the clock and this entry overlaps it, try with earlier times.');
110110
} else {
111111
this.doSave(event);

0 commit comments

Comments
 (0)