2022-09-12 14:47:27 -08:00
|
|
|
<template>
|
|
|
|
{{ value }}
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2022-12-09 20:57:57 -09:00
|
|
|
type DateTimeFormat = "relative" | "long" | "short" | "human";
|
|
|
|
|
2023-01-01 13:50:48 -08:00
|
|
|
type Props = {
|
|
|
|
date?: Date | string;
|
|
|
|
format?: DateTimeFormat;
|
|
|
|
};
|
|
|
|
|
|
|
|
const props = withDefaults(defineProps<Props>(), {
|
|
|
|
date: undefined,
|
|
|
|
format: "relative",
|
|
|
|
});
|
2022-12-09 20:57:57 -09:00
|
|
|
|
2022-09-12 14:47:27 -08:00
|
|
|
const value = computed(() => {
|
2023-01-01 13:50:48 -08:00
|
|
|
if (!props.date || !validDate(props.date)) {
|
2022-09-12 14:47:27 -08:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2023-01-01 13:50:48 -08:00
|
|
|
return fmtDate(props.date, props.format);
|
2022-09-12 14:47:27 -08:00
|
|
|
});
|
|
|
|
</script>
|