diff --git a/src/app/modules/reports/components/time-entries-table/time-entries-table.component.html b/src/app/modules/reports/components/time-entries-table/time-entries-table.component.html
index 20119c648..4b509a983 100644
--- a/src/app/modules/reports/components/time-entries-table/time-entries-table.component.html
+++ b/src/app/modules/reports/components/time-entries-table/time-entries-table.component.html
@@ -1,5 +1,5 @@
+Total: {{this.resultSum.hours}} hours, {{this.resultSum.minutes}} minutes
\ No newline at end of file
diff --git a/src/app/modules/reports/components/time-entries-table/time-entries-table.component.spec.ts b/src/app/modules/reports/components/time-entries-table/time-entries-table.component.spec.ts
index 1263c4706..559a13b93 100644
--- a/src/app/modules/reports/components/time-entries-table/time-entries-table.component.spec.ts
+++ b/src/app/modules/reports/components/time-entries-table/time-entries-table.component.spec.ts
@@ -7,6 +7,7 @@ import { SubstractDatePipe } from 'src/app/modules/shared/pipes/substract-date/s
import { getReportDataSource } from 'src/app/modules/time-clock/store/entry.selectors';
import { EntryState } from '../../../time-clock/store/entry.reducer';
import { TimeEntriesTableComponent } from './time-entries-table.component';
+import { TotalHours } from '../../models/total-hours-report';
import { ActionsSubject } from '@ngrx/store';
import { UserActionTypes } from 'src/app/modules/users/store';
@@ -32,6 +33,31 @@ describe('Reports Page', () => {
project_name: 'Time-Tracker',
};
+ const timeEntryList: Entry[] = [
+ {
+ id: '123',
+ start_date: new Date('2022-04-24T11:30:00Z'),
+ end_date: new Date('2022-04-24T14:30:00Z'),
+ activity_id: '123',
+ technologies: ['react', 'redux'],
+ description: 'any comment',
+ uri: 'custom uri',
+ project_id: '123',
+ project_name: 'Time-Tracker',
+ },
+ {
+ id: '456',
+ start_date: new Date('2022-04-25T12:40:00Z'),
+ end_date: new Date('2022-04-25T13:00:00Z'),
+ activity_id: '123',
+ technologies: ['react', 'redux'],
+ description: 'any comment',
+ uri: 'custom uri',
+ project_id: '123',
+ project_name: 'Time-Tracker',
+ }
+ ];
+
const state: EntryState = {
active: timeEntry,
isLoading: false,
@@ -175,6 +201,11 @@ describe('Reports Page', () => {
expect(component.users).toEqual(usersArray);
});
+
+ it('The sum of the data dates is equal to {"hours": 3, "minutes":20,"seconds":0}', () => {
+ let {hours,minutes,seconds}: TotalHours = component.sumDates(timeEntryList);
+ expect({hours, minutes, seconds}).toEqual({hours:3,minutes:20,seconds:0});
+ });
afterEach(() => {
fixture.destroy();
diff --git a/src/app/modules/reports/components/time-entries-table/time-entries-table.component.ts b/src/app/modules/reports/components/time-entries-table/time-entries-table.component.ts
index c089c5996..cfa6f98ee 100644
--- a/src/app/modules/reports/components/time-entries-table/time-entries-table.component.ts
+++ b/src/app/modules/reports/components/time-entries-table/time-entries-table.component.ts
@@ -9,6 +9,7 @@ import { Entry } from 'src/app/modules/shared/models';
import { DataSource } from 'src/app/modules/shared/models/data-source.model';
import { EntryState } from '../../../time-clock/store/entry.reducer';
import { getReportDataSource } from '../../../time-clock/store/entry.selectors';
+import { TotalHours } from '../../models/total-hours-report';
import { User } from 'src/app/modules/users/models/users';
import { LoadUsers, UserActionTypes } from 'src/app/modules/users/store/user.actions';
import { ParseDateTimeOffset } from '../../../shared/formatters/parse-date-time-offset/parse-date-time-offset';
@@ -67,6 +68,7 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
isLoading$: Observable;
reportDataSource$: Observable>;
rerenderTableSubscription: Subscription;
+ resultSum: TotalHours;
dateTimeOffset: ParseDateTimeOffset;
constructor(private store: Store, private actionsSubject$: ActionsSubject, private storeUser: Store ) {
@@ -85,6 +87,7 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
ngOnInit(): void {
this.rerenderTableSubscription = this.reportDataSource$.subscribe((ds) => {
+ this.sumDates(ds.data);
this.rerenderDataTable();
});
this.uploadUsers();
@@ -124,6 +127,26 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
const durationColumnIndex = 3;
return column === durationColumnIndex ? moment.duration(dataFormated).asHours().toFixed(2) : dataFormated;
}
+
+ sumDates(arrayData: Entry[]): TotalHours{
+ this.resultSum = new TotalHours();
+ let arrayDurations= new Array();
+ arrayData.forEach(entry =>{
+ let start = moment(entry.end_date).diff(moment(entry.start_date));
+ arrayDurations.push(moment.utc(start).format("HH:mm:ss"));
+ });
+
+ let totalDurations = arrayDurations.slice(1)
+ .reduce((prev, cur) => {
+ return prev.add(cur);
+ },
+ moment.duration(arrayDurations[0]));
+ let daysInHours = totalDurations.days() * 24;
+ this.resultSum.hours=totalDurations.hours() + daysInHours;
+ this.resultSum.minutes = totalDurations.minutes();
+ this.resultSum.seconds = totalDurations.seconds();
+ return this.resultSum;
+ }
user(userId: string){
this.selectedUserId.emit(userId);
diff --git a/src/app/modules/reports/models/total-hours-report.ts b/src/app/modules/reports/models/total-hours-report.ts
new file mode 100644
index 000000000..0dc49b541
--- /dev/null
+++ b/src/app/modules/reports/models/total-hours-report.ts
@@ -0,0 +1,12 @@
+export class TotalHours {
+
+ hours: number;
+ minutes: number;
+ seconds: number;
+
+ constructor() {
+ this.hours = 0;
+ this.minutes = 0;
+ this.seconds = 0;
+ }
+}
\ No newline at end of file