Skip to content
Next Next commit
Create function to sum dates
  • Loading branch information
sbateca committed Mar 28, 2022
commit 0927f1e3482f8698cad8690c02dc3268d7768a22
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn

ngOnInit(): void {
this.rerenderTableSubscription = this.reportDataSource$.subscribe((ds) => {
this.sumDates(ds.data);
this.rerenderDataTable();
});
}
Expand Down Expand Up @@ -105,5 +106,30 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
const durationColumnIndex = 3;
return column === durationColumnIndex ? moment.duration(dataFormated).asHours().toFixed(2) : dataFormated;
}

sumDates(arrayData: Entry[]){

let totalDaysInHours: number = 0;
let totalHours: number = 0;
let totalMinutes: number = 0;
let totalSeconds: number = 0;

arrayData.forEach(entry =>{
let duration = this.getTimeDifference(moment(entry.end_date),moment(entry.start_date));
totalDaysInHours += duration.days() >= 1 ? duration.days() * 24 : 0;
totalHours += duration.hours();
totalMinutes += duration.minutes();
totalSeconds += duration.seconds();


console.log(`Horas: ${totalHours} Minutos: ${totalMinutes} Segundos: ${totalSeconds}`);

});
}

getTimeDifference(substractDate: moment.Moment, fromDate: moment.Moment): moment.Duration {
return moment.duration(fromDate.diff(substractDate));
}

}