Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use custom traveled time formatter in metadata view #98

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ 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 +44,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 +82,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')}`;
}
}
Loading