<template>
  <div>{{ clock }}</div>
</template>

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

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

  @Prop()
  format!: string;

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

  private beforeDestroy(): void {
    // prevent memory leak
    clearInterval(this.interval);
  }
}
</script>

<style>
</style>