Skip to content

Commit

Permalink
Use custom traveled time formatter in metadata view
Browse files Browse the repository at this point in the history
  • Loading branch information
jmccollum-woolpert committed Nov 2, 2023
1 parent 059fc96 commit 8926b35
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@
</td>
</ng-container>
<ng-container matColumnDef="traveledTime">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Traveled time</th>
<th mat-header-cell *matHeaderCellDef mat-sort-header>Traveled time (hh:mm)</th>
<td mat-cell *matCellDef="let item">
{{ durationFormatter(item.traveledTime) }}
{{ formattedTravelTime(item.traveledTime) }}
</td>
</ng-container>
<ng-container matColumnDef="cost">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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) {}
Expand Down Expand Up @@ -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')}`;
}
}

0 comments on commit 8926b35

Please sign in to comment.