Skip to content

Commit 3aba038

Browse files
committed
fix: Calculate plan preview end time
Signed-off-by: Gernot Pansy <[email protected]>
1 parent 7924922 commit 3aba038

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

assets/js/components/ChargingPlans/Preview.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,12 @@ export default defineComponent({
144144
base.setSeconds(0, 0);
145145
base.setMinutes(base.getMinutes() - (base.getMinutes() % 15));
146146
147-
return Array.from({ length: 48 * 4 }, (_, i) => {
147+
const endTime = this.getMaxEndTime([...rates, ...plan]);
148+
const interval = endTime
149+
? Math.ceil((endTime - base.getTime()) / 1000 / 60 / 15)
150+
: 48 * 4; // Default to 48 hours if no end time
151+
152+
return Array.from({ length: interval }, (_, i) => {
148153
const start = new Date(base.getTime() + quarterHour * i);
149154
const end = new Date(start.getTime() + quarterHour);
150155
const charging = !!this.findSlotInRange(start, end, plan);
@@ -197,6 +202,12 @@ export default defineComponent({
197202
slotHovered(index: number): void {
198203
this.activeIndex = index;
199204
},
205+
getMaxEndTime(list: Rate[]): Date | null {
206+
if (!list.length) {
207+
return null;
208+
}
209+
return Math.max(...list.map((s) => s.end.getTime()));
210+
},
200211
},
201212
});
202213
</script>

0 commit comments

Comments
 (0)