Skip to content

Commit 128c5d2

Browse files
committed
improve function that calculate the sum
1 parent 0927f1e commit 128c5d2

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { Entry } from 'src/app/modules/shared/models';
88
import { DataSource } from 'src/app/modules/shared/models/data-source.model';
99
import { EntryState } from '../../../time-clock/store/entry.reducer';
1010
import { getReportDataSource } from '../../../time-clock/store/entry.selectors';
11+
import { Moment } from 'moment';
12+
import { TotalHours } from '../../models/total-hours-report';
1113

1214
@Component({
1315
selector: 'app-time-entries-table',
@@ -107,12 +109,13 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
107109
return column === durationColumnIndex ? moment.duration(dataFormated).asHours().toFixed(2) : dataFormated;
108110
}
109111

110-
sumDates(arrayData: Entry[]){
112+
sumDates(arrayData: Entry[]): TotalHours{
111113

112114
let totalDaysInHours: number = 0;
113115
let totalHours: number = 0;
114116
let totalMinutes: number = 0;
115117
let totalSeconds: number = 0;
118+
let resultSum: TotalHours;
116119

117120
arrayData.forEach(entry =>{
118121
let duration = this.getTimeDifference(moment(entry.end_date),moment(entry.start_date));
@@ -121,10 +124,11 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
121124
totalMinutes += duration.minutes();
122125
totalSeconds += duration.seconds();
123126

127+
console.log(resultSum);
124128

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

127130
});
131+
return resultSum;
128132
}
129133

130134
getTimeDifference(substractDate: moment.Moment, fromDate: moment.Moment): moment.Duration {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export interface TotalHours {
2+
totalHours: number;
3+
totalMinutes: number;
4+
totalSeconds: number;
5+
}

0 commit comments

Comments
 (0)