Skip to content

Commit 0927f1e

Browse files
committed
Create function to sum dates
1 parent da1792f commit 0927f1e

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/app/modules/reports/components/time-entries-table/time-entries-table.component.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
6767

6868
ngOnInit(): void {
6969
this.rerenderTableSubscription = this.reportDataSource$.subscribe((ds) => {
70+
this.sumDates(ds.data);
7071
this.rerenderDataTable();
7172
});
7273
}
@@ -105,5 +106,30 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
105106
const durationColumnIndex = 3;
106107
return column === durationColumnIndex ? moment.duration(dataFormated).asHours().toFixed(2) : dataFormated;
107108
}
109+
110+
sumDates(arrayData: Entry[]){
111+
112+
let totalDaysInHours: number = 0;
113+
let totalHours: number = 0;
114+
let totalMinutes: number = 0;
115+
let totalSeconds: number = 0;
116+
117+
arrayData.forEach(entry =>{
118+
let duration = this.getTimeDifference(moment(entry.end_date),moment(entry.start_date));
119+
totalDaysInHours += duration.days() >= 1 ? duration.days() * 24 : 0;
120+
totalHours += duration.hours();
121+
totalMinutes += duration.minutes();
122+
totalSeconds += duration.seconds();
123+
124+
125+
console.log(`Horas: ${totalHours} Minutos: ${totalMinutes} Segundos: ${totalSeconds}`);
126+
127+
});
128+
}
129+
130+
getTimeDifference(substractDate: moment.Moment, fromDate: moment.Moment): moment.Duration {
131+
return moment.duration(fromDate.diff(substractDate));
132+
}
133+
108134
}
109135

0 commit comments

Comments
 (0)