2022-09-12 22:47:27 +00:00
|
|
|
<template>
|
|
|
|
{{ value }}
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2024-03-01 17:21:45 +00:00
|
|
|
import type { DateTimeFormat, DateTimeType } from "~~/composables/use-formatters";
|
2022-12-10 05:57:57 +00:00
|
|
|
|
2023-01-01 21:50:48 +00:00
|
|
|
type Props = {
|
|
|
|
date?: Date | string;
|
|
|
|
format?: DateTimeFormat;
|
2023-02-28 04:52:56 +00:00
|
|
|
datetimeType?: DateTimeType;
|
2023-01-01 21:50:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const props = withDefaults(defineProps<Props>(), {
|
|
|
|
date: undefined,
|
|
|
|
format: "relative",
|
2023-02-28 04:52:56 +00:00
|
|
|
datetimeType: "date",
|
2023-01-01 21:50:48 +00:00
|
|
|
});
|
2022-12-10 05:57:57 +00:00
|
|
|
|
2022-09-12 22:47:27 +00:00
|
|
|
const value = computed(() => {
|
2023-01-01 21:50:48 +00:00
|
|
|
if (!props.date || !validDate(props.date)) {
|
2022-09-12 22:47:27 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2024-02-29 18:58:26 +00:00
|
|
|
return fmtDate(props.date, props.format);
|
2022-09-12 22:47:27 +00:00
|
|
|
});
|
|
|
|
</script>
|