evcc-io/assets/js/components/Forecast/ActiveSlot.vue
2025-10-03 16:45:56 +02:00

47 lines
1.4 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div v-if="isSlot" class="text-end tabular">
<span class="text-nowrap">{{ day }} {{ start }}</span
>{{ " " }}<span class="text-nowrap">– {{ end }}</span>
</div>
<div v-if="isTimeseries" class="text-end tabular">
<span class="text-nowrap">{{ time }}</span>
</div>
</template>
<script lang="ts">
import { defineComponent, type PropType } from "vue";
import formatter from "@/mixins/formatter";
import { isForecastSlot, type ForecastSlot, type TimeseriesEntry } from "./types";
export default defineComponent({
name: "ForecastActiveSlot",
mixins: [formatter],
props: {
activeSlot: { type: Object as PropType<ForecastSlot | TimeseriesEntry | null> },
},
computed: {
isSlot() {
return this.activeSlot !== null && isForecastSlot(this.activeSlot);
},
isTimeseries() {
return this.activeSlot !== null && !isForecastSlot(this.activeSlot);
},
day() {
const startDate = new Date((this.activeSlot! as ForecastSlot).start);
return this.weekdayShort(startDate);
},
start() {
const startDate = new Date((this.activeSlot! as ForecastSlot).start);
return this.fmtHourMinute(startDate);
},
end() {
const endDate = new Date((this.activeSlot! as ForecastSlot).end);
return this.fmtHourMinute(endDate);
},
time() {
const time = new Date((this.activeSlot! as TimeseriesEntry).ts);
return `${this.weekdayShort(time)} ${this.fmtHourMinute(time)}`;
},
},
});
</script>