@@ -32,6 +32,14 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
3232 selectedYear : number ;
3333 selectedMonthAsText : string ;
3434
35+ startDateAsLocalDate : Date ;
36+ endDateAsLocalDate : Date ;
37+ activeEntryAsLocalDate : Date ;
38+ isEditingEntryEqualToActiveEntry ;
39+ isStartDateGreaterThanActiveEntry ;
40+ isEndDateGreaterThanActiveEntry ;
41+ isTimeEntryOverlapping ;
42+
3543 constructor ( private store : Store < EntryState > , private toastrService : ToastrService , private actionsSubject$ : ActionsSubject ) {
3644 this . timeEntriesDataSource$ = this . store . pipe ( delay ( 0 ) , select ( getTimeEntriesDataSource ) ) ;
3745 }
@@ -105,17 +113,17 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
105113
106114 saveEntry ( event : SaveEntryEvent ) : void {
107115 if ( this . activeTimeEntry ) {
108- const startDateAsLocalDate = new Date ( event . entry . start_date ) ;
109- const endDateAsLocalDate = new Date ( event . entry . end_date ) ;
110- const activeEntryAsLocalDate = new Date ( this . activeTimeEntry . start_date ) ;
111- const isEditingEntryEqualToActiveEntry = this . entryId === this . activeTimeEntry . id ;
112- const isStartDateGreaterThanActiveEntry = startDateAsLocalDate > activeEntryAsLocalDate ;
113- const isEndDateGreaterThanActiveEntry = endDateAsLocalDate > activeEntryAsLocalDate ;
114- const isTimeEntryOverlapping = isStartDateGreaterThanActiveEntry || isEndDateGreaterThanActiveEntry ;
115- if ( ! isEditingEntryEqualToActiveEntry && isTimeEntryOverlapping ) {
116- this . toastrService . error ( 'You are on the clock and this entry overlaps it, try with earlier times.' ) ;
117- } else {
116+ this . startDateAsLocalDate = new Date ( event . entry . start_date ) ;
117+ this . endDateAsLocalDate = new Date ( event . entry . end_date ) ;
118+ this . activeEntryAsLocalDate = new Date ( this . activeTimeEntry . start_date ) ;
119+ this . isEditingEntryEqualToActiveEntry = this . entryId === this . activeTimeEntry . id ;
120+ this . isStartDateGreaterThanActiveEntry = this . startDateAsLocalDate > this . activeEntryAsLocalDate ;
121+ this . isEndDateGreaterThanActiveEntry = this . endDateAsLocalDate > this . activeEntryAsLocalDate ;
122+ this . isTimeEntryOverlapping = this . isStartDateGreaterThanActiveEntry || this . isEndDateGreaterThanActiveEntry ;
123+ if ( this . isEditingEntryEqualToActiveEntry && ! this . isTimeEntryOverlapping ) {
118124 this . doSave ( event ) ;
125+ } else {
126+ this . toastrService . error ( 'You are on the clock and this entry overlaps it, try with earlier times.' ) ;
119127 }
120128 } else {
121129 this . doSave ( event ) ;
0 commit comments