<template>
  <div>{{ formatted }}</div>
</template>

<script lang="ts">
import { Component, Prop, Vue } from "vue-property-decorator";
import { DateTime } from "luxon";

@Component
export default class Clock extends Vue {
  private formatted = "";
  private interval?: number;

  @Prop()
  public format!: string;

  public created(): void {
    this.interval = setInterval((): void => {
      this.formatted = DateTime.now()
        .setLocale(navigator.language)
        .toFormat(this.format);
    }, 1000);
  }

  public beforeDestroy(): void {
    clearInterval(this.interval);
  }
}
</script>

<style>
</style>