Skip to content

Commit 3c6234b

Browse files
committed
hack: allow times to be unset
1 parent 4045895 commit 3c6234b

File tree

4 files changed

+22
-25
lines changed

4 files changed

+22
-25
lines changed

src/app/data-structures/technical.data.structures.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export interface TimeFormatter {
9898
* Represents the time data in TrainrunSectionDto.
9999
*/
100100
export interface TimeLockDto {
101-
time: number; // minutes [0..60]
101+
time: number | null; // minutes [0..60]
102102
consecutiveTime: number; // automatically updated after any data changes in the application
103103
lock: boolean; // used to stop the time propagation (forward/backward)
104104
warning: WarningDto; // warning - if business logic detects an issue -> set human-readable warning

src/app/models/trainrunsection.model.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ export class TrainrunSection {
175175
}
176176

177177
private static formatDisplayText(time: TimeLockDto, offset: number): string {
178+
if (time.time === null) {
179+
return "?";
180+
}
178181
if (!time?.timeFormatter?.stylePattern) {
179182
return undefined;
180183
}

src/app/services/data/trainrun-section-times.service.ts

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -491,22 +491,22 @@ export class TrainrunSectionTimesService {
491491
this.initialLeftAndRightElement ===
492492
LeftAndRightElement.LeftRightTrainrunName
493493
) {
494-
this.timeStructure.leftDepartureTime =
494+
this.timeStructure.leftDepartureTime = this.timeStructure.leftDepartureTime === null ? null :
495495
(this.timeStructure.leftDepartureTime + this.offset) % 60;
496-
this.timeStructure.rightArrivalTime =
496+
this.timeStructure.rightArrivalTime = this.timeStructure.rightArrivalTime === null ? null :
497497
(this.timeStructure.rightArrivalTime + this.offset) % 60;
498-
this.timeStructure.leftArrivalTime =
498+
this.timeStructure.leftArrivalTime = this.timeStructure.leftArrivalTime === null ? null :
499499
(maxMinutes + this.timeStructure.leftArrivalTime - this.offset) % 60;
500-
this.timeStructure.rightDepartureTime =
500+
this.timeStructure.rightDepartureTime = this.timeStructure.rightDepartureTime === null ? null :
501501
(maxMinutes + this.timeStructure.rightDepartureTime - this.offset) % 60;
502502
} else {
503-
this.timeStructure.leftDepartureTime =
503+
this.timeStructure.leftDepartureTime = this.timeStructure.leftDepartureTime === null ? null :
504504
(maxMinutes + this.timeStructure.leftDepartureTime - this.offset) % 60;
505-
this.timeStructure.rightArrivalTime =
505+
this.timeStructure.rightArrivalTime = this.timeStructure.rightArrivalTime === null ? null :
506506
(maxMinutes + this.timeStructure.rightArrivalTime - this.offset) % 60;
507-
this.timeStructure.leftArrivalTime =
507+
this.timeStructure.leftArrivalTime = this.timeStructure.leftArrivalTime === null ? null :
508508
(this.timeStructure.leftArrivalTime + this.offset) % 60;
509-
this.timeStructure.rightDepartureTime =
509+
this.timeStructure.rightDepartureTime = this.timeStructure.rightDepartureTime === null ? null :
510510
(this.timeStructure.rightDepartureTime + this.offset) % 60;
511511
}
512512
this.offsetTransformationActive = true;
@@ -573,21 +573,15 @@ export class TrainrunSectionTimesService {
573573

574574
private fixAllTimesPrecision() {
575575
const timeDisplayPrecision = 1000;
576-
this.timeStructure.leftArrivalTime =
577-
Math.round(this.timeStructure.leftArrivalTime * timeDisplayPrecision) /
578-
timeDisplayPrecision;
579-
this.timeStructure.leftDepartureTime =
580-
Math.round(this.timeStructure.leftDepartureTime * timeDisplayPrecision) /
581-
timeDisplayPrecision;
582-
this.timeStructure.rightArrivalTime =
583-
Math.round(this.timeStructure.rightArrivalTime * timeDisplayPrecision) /
584-
timeDisplayPrecision;
585-
this.timeStructure.rightDepartureTime =
586-
Math.round(this.timeStructure.rightDepartureTime * timeDisplayPrecision) /
587-
timeDisplayPrecision;
588-
this.timeStructure.travelTime =
589-
Math.round(this.timeStructure.travelTime * timeDisplayPrecision) /
590-
timeDisplayPrecision;
576+
const fixPrecision = (time) => {
577+
if (time === null) return null;
578+
return Math.round(time * timeDisplayPrecision) / timeDisplayPrecision;
579+
};
580+
this.timeStructure.leftArrivalTime = fixPrecision(this.timeStructure.leftArrivalTime);
581+
this.timeStructure.leftDepartureTime = fixPrecision(this.timeStructure.leftDepartureTime);
582+
this.timeStructure.rightArrivalTime = fixPrecision(this.timeStructure.rightArrivalTime);
583+
this.timeStructure.rightDepartureTime = fixPrecision(this.timeStructure.rightDepartureTime);
584+
this.timeStructure.travelTime = fixPrecision(this.timeStructure.travelTime);
591585
}
592586

593587
private updateTrainrunSectionTime() {

src/app/services/util/trainrunsection.helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ export class TrainrunsectionHelper {
303303
leftArrivalTime: lastLeftNode.getArrivalTime(leftTrainrunSection),
304304
rightDepartureTime: lastRightNode.getDepartureTime(rightTrainrunSection),
305305
rightArrivalTime: lastRightNode.getArrivalTime(rightTrainrunSection),
306-
travelTime: cumulativeTravelTime,
306+
travelTime: cumulativeTravelTime || null,
307307
};
308308
}
309309

0 commit comments

Comments
 (0)