Skip to content

Commit 3eaff62

Browse files
tpd-opitzbenderl
andauthored
Update ElectricityTariffCard.vue - fix: PriceChart last entry ends midnight regardless of price data resolution (#807)
* Update ElectricityTariffCard.vue - fix: PriceChart last entry ends midnight regardless of price data resolution * Update ElectricityTariffCard.vue - timstamp of last entry use diff of timestamps * Enhance tick label formatting to show "morgen" Add callback to format tick labels based on date. * Fix indentation and formatting in ElectricityTariffCard.vue * Update src/components/status/ElectricityTariffCard.vue use backticks Co-authored-by: benderl <[email protected]> * Refactor date comparison for tomorrow check * Update src/components/status/ElectricityTariffCard.vue Co-authored-by: benderl <[email protected]> * restructure changes * fix locale always use `undefined` as locale to use client time format --------- Co-authored-by: benderl <[email protected]> Co-authored-by: Lutz Bender <[email protected]>
1 parent 92ea0ef commit 3eaff62

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/components/status/ElectricityTariffCard.vue

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export default {
137137
font: {
138138
size: 12,
139139
},
140+
callback: this.formatTickLabel,
140141
// color: tickColor,
141142
maxTicksLimit: 0,
142143
},
@@ -198,10 +199,17 @@ export default {
198199
price: value * 100000,
199200
});
200201
}
201-
// repeat last dataset with 59min 59sec offset
202+
// repeat last dataset
202203
const lastData = myData.slice(-1)[0];
204+
// midnight as default
205+
let nextTimestamp = this.endOfToday;
206+
if (myData.length > 1) {
207+
// same offset minus 1ms as the last one
208+
const previousData = myData.slice(-2, -1)[0];
209+
nextTimestamp = lastData.timestamp + lastData.timestamp - previousData.timestamp - 1;
210+
}
203211
myData.push({
204-
timestamp: lastData.timestamp + (60 * 60 - 1) * 1000,
212+
timestamp: nextTimestamp,
205213
price: lastData.price,
206214
});
207215
}
@@ -215,12 +223,24 @@ export default {
215223
}
216224
return this.formatNumber(this.chartDataObject.datasets[0].data[0].price || 0, 2);
217225
},
226+
endOfToday() {
227+
return new Date().setHours(23, 59, 59, 999).valueOf();
228+
},
218229
baseTopic: {
219230
get() {
220231
return "openWB/optional/et";
221232
},
222233
},
223234
},
235+
methods: {
236+
formatTickLabel(timeValue) {
237+
const date = new Date(timeValue);
238+
// Prüfe ob das Datum zum nächsten Tag gehört
239+
const isTomorrow = this.endOfToday < date;
240+
// Zeige nur den Zeitwert, wenn es nicht morgen ist
241+
return `${isTomorrow ? date.toLocaleDateString(undefined, { day: "2-digit", month: "2-digit" }) + " " : ""}${date.toLocaleTimeString(undefined, { hour: "2-digit", minute: "2-digit" })}`;
242+
},
243+
},
224244
};
225245
</script>
226246

0 commit comments

Comments
 (0)