From 8926b35ed8123a8d9200a95e91b68e60cdafd895 Mon Sep 17 00:00:00 2001 From: Jason McCollum Date: Thu, 2 Nov 2023 15:29:45 -0700 Subject: [PATCH 1/3] Use custom traveled time formatter in metadata view --- .../base-routes-metadata-table.component.html | 4 ++-- .../base-routes-metadata-table.component.ts | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/application/frontend/src/app/routes-metadata/components/base-routes-metadata-table/base-routes-metadata-table.component.html b/application/frontend/src/app/routes-metadata/components/base-routes-metadata-table/base-routes-metadata-table.component.html index eea68fe5..88d78b54 100644 --- a/application/frontend/src/app/routes-metadata/components/base-routes-metadata-table/base-routes-metadata-table.component.html +++ b/application/frontend/src/app/routes-metadata/components/base-routes-metadata-table/base-routes-metadata-table.component.html @@ -74,9 +74,9 @@ - Traveled time + Traveled time (hh:mm) - {{ durationFormatter(item.traveledTime) }} + {{ formattedTravelTime(item.traveledTime) }} diff --git a/application/frontend/src/app/routes-metadata/components/base-routes-metadata-table/base-routes-metadata-table.component.ts b/application/frontend/src/app/routes-metadata/components/base-routes-metadata-table/base-routes-metadata-table.component.ts index 878f9df1..a6c34006 100644 --- a/application/frontend/src/app/routes-metadata/components/base-routes-metadata-table/base-routes-metadata-table.component.ts +++ b/application/frontend/src/app/routes-metadata/components/base-routes-metadata-table/base-routes-metadata-table.component.ts @@ -18,7 +18,10 @@ import { ViewEncapsulation, } from '@angular/core'; import { DataSource } from 'src/app/shared/models'; -import { formatDuration, getCapacityQuantityUnit, getUnitAbbreviation } from 'src/app/util'; +import { + getCapacityQuantityUnit, + getUnitAbbreviation, +} from 'src/app/util'; import { RouteMetadata } from '../../models'; import { selectAllowExperimentalFeatures } from '../../../../app/core/selectors/config.selectors'; import { Store } from '@ngrx/store'; @@ -44,7 +47,6 @@ export class BaseRoutesMetadataTableComponent implements OnInit { @Output() sortChange = new EventEmitter<{ active: string; direction: string }>(); allowExperimentalFeatures: boolean; - durationFormatter = formatDuration; objectKeys = Object.keys; constructor(private store: Store, private zone: NgZone) {} @@ -83,4 +85,10 @@ export class BaseRoutesMetadataTableComponent implements OnInit { onSortChange(value: { active: string; direction: string }): void { this.zone.run(() => this.sortChange.emit(value)); } + + formattedTravelTime(seconds: number): string { + const hours = Math.floor(seconds / 3600); + const minutes = Math.floor((seconds - hours * 3600) / 60); + return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}`; + } } From 866008e8bcd9a1ae646b27bcb791eee97d172fd8 Mon Sep 17 00:00:00 2001 From: Jason McCollum Date: Mon, 6 Nov 2023 09:01:28 -0800 Subject: [PATCH 2/3] Fix code style --- .../base-routes-metadata-table.component.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/application/frontend/src/app/routes-metadata/components/base-routes-metadata-table/base-routes-metadata-table.component.ts b/application/frontend/src/app/routes-metadata/components/base-routes-metadata-table/base-routes-metadata-table.component.ts index a6c34006..cd7ee83a 100644 --- a/application/frontend/src/app/routes-metadata/components/base-routes-metadata-table/base-routes-metadata-table.component.ts +++ b/application/frontend/src/app/routes-metadata/components/base-routes-metadata-table/base-routes-metadata-table.component.ts @@ -18,10 +18,7 @@ import { ViewEncapsulation, } from '@angular/core'; import { DataSource } from 'src/app/shared/models'; -import { - getCapacityQuantityUnit, - getUnitAbbreviation, -} from 'src/app/util'; +import { getCapacityQuantityUnit, getUnitAbbreviation } from 'src/app/util'; import { RouteMetadata } from '../../models'; import { selectAllowExperimentalFeatures } from '../../../../app/core/selectors/config.selectors'; import { Store } from '@ngrx/store'; From 7be96f6e2056e866ac677519a02b2de40703236e Mon Sep 17 00:00:00 2001 From: Jason McCollum Date: Mon, 6 Nov 2023 09:56:13 -0800 Subject: [PATCH 3/3] Add additional unit tests --- .../base-routes-metadata-table.component.spec.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/application/frontend/src/app/routes-metadata/components/base-routes-metadata-table/base-routes-metadata-table.component.spec.ts b/application/frontend/src/app/routes-metadata/components/base-routes-metadata-table/base-routes-metadata-table.component.spec.ts index d327f0c0..468004c0 100644 --- a/application/frontend/src/app/routes-metadata/components/base-routes-metadata-table/base-routes-metadata-table.component.spec.ts +++ b/application/frontend/src/app/routes-metadata/components/base-routes-metadata-table/base-routes-metadata-table.component.spec.ts @@ -52,4 +52,15 @@ describe('BaseRoutesMetadataTableComponent', () => { it('should create', () => { expect(component).toBeTruthy(); }); + + it('should format traveled time', () => { + expect(component.formattedTravelTime(0)).toBe('00:00'); + expect(component.formattedTravelTime(61)).toBe('00:01'); + expect(component.formattedTravelTime(1910)).toBe('00:31'); + expect(component.formattedTravelTime(3600)).toBe('01:00'); + expect(component.formattedTravelTime(7260)).toBe('02:01'); + expect(component.formattedTravelTime(7300)).toBe('02:01'); + expect(component.formattedTravelTime(86400)).toBe('24:00'); + expect(component.formattedTravelTime(90120)).toBe('25:02'); + }); });