ovdashboard/ui/src/components/title/Clock.vue

33 lines
666 B
Vue
Raw Normal View History

2022-09-09 22:41:50 +00:00
<template>
2022-09-10 13:11:48 +00:00
<span>{{ formatted }}</span>
2022-09-09 22:41:50 +00:00
</template>
<script lang="ts">
2022-09-10 02:11:36 +00:00
import { DateTime } from "luxon";
2023-10-26 22:28:59 +00:00
import { Component, Prop, Vue } from "vue-property-decorator";
2022-09-09 22:41:50 +00:00
2022-09-09 23:14:03 +00:00
@Component
2022-09-10 02:19:45 +00:00
export default class Clock extends Vue {
2023-10-26 22:28:59 +00:00
public formatted = "";
2022-09-10 02:11:36 +00:00
private interval?: number;
2022-09-09 22:41:50 +00:00
2022-09-12 22:37:55 +00:00
@Prop({ required: true })
private readonly format!: string;
2022-09-09 22:41:50 +00:00
private update(): void {
this.formatted = DateTime.now()
.setLocale(navigator.language)
.toFormat(this.format);
}
2022-09-10 02:19:45 +00:00
public created(): void {
this.update();
this.interval = setInterval(this.update, 10000);
2022-09-09 23:14:03 +00:00
}
2022-09-09 22:41:50 +00:00
2022-09-10 02:19:45 +00:00
public beforeDestroy(): void {
2022-09-10 02:11:36 +00:00
clearInterval(this.interval);
2022-09-09 23:14:03 +00:00
}
}
2022-09-09 22:41:50 +00:00
</script>