ovdashboard/ui/src/components/Clock.vue

32 lines
618 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-09 23:14:03 +00:00
import { Component, Prop, Vue } from "vue-property-decorator";
2022-09-10 02:11:36 +00:00
import { DateTime } from "luxon";
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 {
private formatted = "";
2022-09-10 02:11:36 +00:00
private interval?: number;
2022-09-09 22:41:50 +00:00
2022-09-09 23:14:03 +00:00
@Prop()
2022-09-10 02:19:45 +00:00
public format!: string;
2022-09-09 22:41:50 +00:00
2022-09-10 02:19:45 +00:00
public created(): void {
2022-09-10 02:11:36 +00:00
this.interval = setInterval((): void => {
2022-09-10 02:19:45 +00:00
this.formatted = DateTime.now()
2022-09-10 02:11:36 +00:00
.setLocale(navigator.language)
.toFormat(this.format);
}, 1000);
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>
<style>
</style>