Skip to content

Commit b33eedd

Browse files
committed
fix: TT-20 Calculate time difference when new entries added
1 parent 00b9f22 commit b33eedd

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,11 +524,23 @@ describe('DetailsFieldsComponent', () => {
524524
},
525525
expectedTimeDiff: '00:55',
526526
},
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+
},
527537
];
528538
diffParams.map((param) => {
529539
it(`if [start_date, start_hour] and [end_date, end_hour] diff is ${param.case}`, () => {
530540
component.entryForm.setValue({ ...formValues, ...param.entryDates });
531541
const timeDiff = component.getTimeDifference();
542+
543+
expect(timeDiff).toBe(param.expectedTimeDiff);
532544
expect(timeDiff).toBe(param.expectedTimeDiff);
533545
});
534546
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
130130
this.end_date.setValue($event);
131131
}
132132

133-
getTimeDifference() {
133+
getTimeDifference(): string {
134134
const startDate = moment(`${this.start_date.value} ${this.start_hour.value}`);
135135
const endDate = moment(`${this.end_date.value} ${this.end_hour.value}`);
136136
if (startDate <= endDate) {

0 commit comments

Comments
 (0)