diff options
author | Orangerot <purple@orangerot.dev> | 2024-06-19 00:14:49 +0200 |
---|---|---|
committer | Orangerot <purple@orangerot.dev> | 2024-06-27 12:11:14 +0200 |
commit | 5b8851b6c268d0e93c158908fbfae9f8473db5ff (patch) | |
tree | 7010eb85d86fa2da06ea4ffbcdb01a685d502ae8 /pse-dashboard/src/components/LastUpdate.vue |
Diffstat (limited to 'pse-dashboard/src/components/LastUpdate.vue')
-rw-r--r-- | pse-dashboard/src/components/LastUpdate.vue | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/pse-dashboard/src/components/LastUpdate.vue b/pse-dashboard/src/components/LastUpdate.vue new file mode 100644 index 0000000..b30b254 --- /dev/null +++ b/pse-dashboard/src/components/LastUpdate.vue @@ -0,0 +1,46 @@ +<script setup> +import { computed } from 'vue' +import { useI18n } from 'vue-i18n'; +import dayjs from 'dayjs/esm' +import relativeTime from 'dayjs/esm/plugin/relativeTime' +import utc from 'dayjs/esm/plugin/utc' +import 'dayjs/esm/locale/de.js' +dayjs.extend(relativeTime) +dayjs.extend(utc) + +const props = defineProps({ + iso: { + type: String, + default: "" + }, + unix: { + type: Number, + default: 0 + } +}); + +const { locale } = useI18n(); + +const tzOffset = (new Date()).getTimezoneOffset(); + +// compute difference from given iso string and now whenever data changes +const lastUpdate = computed(() => { + let lastUpdateTime; + + if (props.iso) { + lastUpdateTime = dayjs(props.iso).utc(true); + } else { + // lastUpdateTime = dayjs(props.unix * 1000); + lastUpdateTime = dayjs(props.unix * 1000).utcOffset(tzOffset).utc(true); + } + + return lastUpdateTime.locale(locale.value).fromNow(); +}); + +</script> +<template> + {{ lastUpdate }} +</template> +<style scoped> +</style> + |