Skip to content

Commit d17223f

Browse files
authored
fix: TT-20 calculate time difference when new entries added (#664)
* fix: TT-20 difference hours * fix: TT-20 Calculate Difference * fix: TT-20 unit test * fix: TT-20 testing * fix: TT-20 Calculate time difference when new entries added * fix: TT-20 Calculate time difference when new entries added * fix: TT-20 Calculate time difference when new entries added * fix: TT-20 Calculate time difference when new entries added
1 parent 03cd1f9 commit d17223f

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

src/app/modules/shared/components/details-fields/details-fields.component.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,17 @@
137137
</div>
138138
</div>
139139

140+
<div class="form-group row" *ngIf="!goingToWorkOnThis">
141+
<label class="col-12 col-sm-2">Total Hours:</label>
142+
<div class="col-12 col-sm-4">
143+
<span class="border-tag"
144+
[class.border-tag--disabled]="!(project_id.value && project_name.value)"
145+
>
146+
{{ this.getTimeDifference() }}
147+
</span>
148+
</div>
149+
</div>
150+
140151
<app-technologies
141152
(technologyAdded)="onTechnologiesUpdated($event)"
142153
(technologyRemoved)="onTechnologiesUpdated($event)"

src/app/modules/shared/components/details-fields/details-fields.component.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,10 @@ input[type="date"]::-webkit-clear-button {
108108
background-color: #e9ecef;
109109
opacity: 1;
110110
}
111+
112+
.border-tag {
113+
border: 1px solid $primary;
114+
padding: 10px;
115+
border-radius: 5px;
116+
margin-top: 10px;
117+
}

src/app/modules/shared/components/details-fields/details-fields.component.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,38 @@ describe('DetailsFieldsComponent', () => {
512512
expect(endDateInput.id).toEqual('end_date');
513513
expect(endDateInput.max).toEqual(expectedDate);
514514
});
515+
516+
const diffParams = [
517+
{
518+
case: 'positive should return correctly diff',
519+
entryDates: {
520+
start_date: '2021-04-15',
521+
end_date: '2021-04-15',
522+
start_hour: '18:05',
523+
end_hour: '19:00',
524+
},
525+
expectedTimeDiff: '00:55',
526+
},
527+
{
528+
case: 'negative should return 00:00',
529+
entryDates: {
530+
start_date: '2021-04-15',
531+
end_date: '2021-04-14',
532+
start_hour: '18:05',
533+
end_hour: '17:00',
534+
},
535+
expectedTimeDiff: '00:00',
536+
},
537+
];
538+
diffParams.map((param) => {
539+
it(`if [start_date, start_hour] and [end_date, end_hour] diff is ${param.case}`, () => {
540+
component.entryForm.setValue({ ...formValues, ...param.entryDates });
541+
const timeDiff = component.getTimeDifference();
542+
543+
expect(timeDiff).toBe(param.expectedTimeDiff);
544+
});
545+
});
546+
515547
/*
516548
TODO As part of https://github.com/ioet/time-tracker-ui/issues/424 a new parameter was added to the details-field-component,
517549
and now these couple of tests are failing. A solution to this error might be generate a Test Wrapper Component. More details here:

src/app/modules/shared/components/details-fields/details-fields.component.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,17 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
130130
this.end_date.setValue($event);
131131
}
132132

133+
getTimeDifference(): string {
134+
const startDate = moment(`${this.start_date.value} ${this.start_hour.value}`);
135+
const endDate = moment(`${this.end_date.value} ${this.end_hour.value}`);
136+
if (startDate <= endDate) {
137+
const diffDate = endDate.diff(startDate);
138+
const duration = moment.duration(diffDate);
139+
return moment.utc(duration.asMilliseconds()).format('HH:mm');
140+
}
141+
return '00:00';
142+
}
143+
133144
ngOnChanges(): void {
134145
this.goingToWorkOnThis = this.entryToEdit ? this.entryToEdit.running : false;
135146
this.shouldRestartEntry = false;

0 commit comments

Comments
 (0)