Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,33 @@ describe('TimeEntriesComponent', () => {
expect(component.canMarkEntryAsWIP).toBe(true);
});

it('displays an error when start date of entry is > than active entry start date', async () => {
it('displays an error when start date of entry is greater than active entry start date', async () => {
component.activeTimeEntry = entry;
const newEntry = {
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 greater 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',
Expand Down
16 changes: 9 additions & 7 deletions src/app/modules/time-entries/pages/time-entries.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,17 @@ 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);
if (this.activeTimeEntry) {
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) {
this.toastrService.error('You are on the clock and this entry overlaps it, try with earlier times.');
} else {
const isEditingEntryEqualToActiveEntry = this.entryId === this.activeTimeEntry.id;
const isStartDateLowerThanActiveEntry = startDateAsLocalDate < activeEntryAsLocalDate;
const isEndDateLowerThanActiveEntry = endDateAsLocalDate < activeEntryAsLocalDate;
if(isEditingEntryEqualToActiveEntry && (isStartDateLowerThanActiveEntry || isEndDateLowerThanActiveEntry)){
this.doSave(event);
} else {
this.toastrService.error('You are on the clock and this entry overlaps it, try with earlier times.');
}
} else {
this.doSave(event);
Expand Down