Skip to content

Commit 9c12d25

Browse files
Implement time window formatting
1 parent e8ebb9a commit 9c12d25

File tree

4 files changed

+60
-12
lines changed

4 files changed

+60
-12
lines changed

application/frontend/src/app/core/components/base-pre-solve-vehicle-info-window/base-pre-solve-vehicle-info-window.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
<div class="strong underline">Start Windows</div>
1818
<div *ngIf="startTimeWindows.length; else noStartWindows">
1919
<div *ngFor="let window of startTimeWindows">
20-
<span>{{ window | formatHardTimeWindow }}</span>
20+
<span>{{ window }}</span>
2121
</div>
2222
</div>
2323
<ng-template #noStartWindows>
2424
<div>None</div>
2525
</ng-template>
26-
</div>
26+
</div>

application/frontend/src/app/core/components/base-pre-solve-vehicle-info-window/base-pre-solve-vehicle-info-window.component.ts

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,18 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
import { ChangeDetectionStrategy, Component, Input, OnChanges, SimpleChanges } from '@angular/core';
17-
import { Vehicle } from '../../models';
18-
import { timeWindowToDuration } from 'src/app/util';
16+
import {
17+
ChangeDetectionStrategy,
18+
Component,
19+
Inject,
20+
Input,
21+
LOCALE_ID,
22+
OnChanges,
23+
SimpleChanges,
24+
} from '@angular/core';
25+
import { ITimeWindow, Vehicle } from '../../models';
26+
import { durationSeconds } from 'src/app/util/duration';
27+
import { formatDate } from '@angular/common';
1928

2029
@Component({
2130
selector: 'app-base-pre-solve-vehicle-info-window',
@@ -25,15 +34,14 @@ import { timeWindowToDuration } from 'src/app/util';
2534
})
2635
export class BasePreSolveVehicleInfoWindowComponent implements OnChanges {
2736
@Input() vehicle: Vehicle;
37+
@Input() timezoneOffset = 0;
38+
@Input() globalDuration: [Long, Long];
2839

2940
loadLimitsNames: string[] = [];
3041
loadLimitsValues: string[] = [];
31-
startTimeWindows: {
32-
startDate: string;
33-
startTime: string;
34-
endDate?: string;
35-
endTime: string;
36-
}[] = [];
42+
startTimeWindows: string[] = [];
43+
44+
constructor(@Inject(LOCALE_ID) private locale: string) {}
3745

3846
ngOnChanges(_changes: SimpleChanges): void {
3947
this.getFormattedLoadLimits();
@@ -42,6 +50,17 @@ export class BasePreSolveVehicleInfoWindowComponent implements OnChanges {
4250

4351
getFormattedTimeWindows(): void {
4452
this.startTimeWindows = [];
53+
54+
if (!this.vehicle || !this.vehicle.startTimeWindows) {
55+
return;
56+
}
57+
58+
this.vehicle.startTimeWindows.forEach((timewindow) => {
59+
if (!timewindow.startTime && !timewindow.endTime) {
60+
return;
61+
}
62+
this.startTimeWindows.push(this.formatTimeWindow(timewindow));
63+
});
4564
}
4665

4766
getFormattedLoadLimits(): void {
@@ -59,4 +78,28 @@ export class BasePreSolveVehicleInfoWindowComponent implements OnChanges {
5978
}
6079
});
6180
}
81+
82+
formatTimeWindow(timewindow: ITimeWindow): string {
83+
const startTime = timewindow.startTime
84+
? durationSeconds(timewindow.startTime).toNumber()
85+
: this.globalDuration[0].toNumber();
86+
const endTime = timewindow.endTime
87+
? durationSeconds(timewindow.endTime).toNumber()
88+
: this.globalDuration[1].toNumber();
89+
90+
const formattedStart = formatDate(
91+
(startTime + this.timezoneOffset) * 1000,
92+
'yyyy/MM/dd h:mm aa',
93+
this.locale,
94+
'UTC'
95+
).toLocaleLowerCase(this.locale);
96+
const formattedEnd = formatDate(
97+
(endTime + this.timezoneOffset) * 1000,
98+
'yyyy/MM/dd h:mm aa',
99+
this.locale,
100+
'UTC'
101+
).toLocaleLowerCase(this.locale);
102+
103+
return `${formattedStart} - ${formattedEnd}`;
104+
}
62105
}

application/frontend/src/app/core/containers/vehicle-info-window/vehicle-info-window.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@
1010

1111
<ng-template #preSolve>
1212
<app-base-pre-solve-vehicle-info-window
13-
[vehicle]="vehicle$ | async"></app-base-pre-solve-vehicle-info-window>
13+
[vehicle]="vehicle$ | async"
14+
[timezoneOffset]="timezoneOffset$ | async"
15+
[globalDuration]="globalDuration$ | async"></app-base-pre-solve-vehicle-info-window>
1416
</ng-template>

application/frontend/src/app/core/containers/vehicle-info-window/vehicle-info-window.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import * as fromVehicle from '../../selectors/vehicle.selectors';
2525
import { map } from 'rxjs/operators';
2626
import * as fromConfig from '../../selectors/config.selectors';
2727
import { selectPage } from '../../selectors/ui.selectors';
28+
import ShipmentModelSelectors from '../../selectors/shipment-model.selectors';
2829

2930
@Component({
3031
selector: 'app-vehicle-info-window',
@@ -40,6 +41,7 @@ export class VehicleInfoWindowComponent implements OnInit {
4041
vehicle$: Observable<Vehicle>;
4142
shipmentCount$: Observable<number>;
4243
timezoneOffset$: Observable<number>;
44+
globalDuration$: Observable<[Long, Long]>;
4345

4446
constructor(private store: Store<fromRoot.State>) {}
4547

@@ -54,6 +56,7 @@ export class VehicleInfoWindowComponent implements OnInit {
5456
select(ShipmentRouteSelectors.selectRouteShipmentCount(this.vehicleId))
5557
);
5658
this.timezoneOffset$ = this.store.pipe(select(fromConfig.selectTimezoneOffset));
59+
this.globalDuration$ = this.store.pipe(select(ShipmentModelSelectors.selectGlobalDuration));
5760
}
5861

5962
onVehicleClick(vehicle: Vehicle): void {

0 commit comments

Comments
 (0)