fix broken datetime

This commit is contained in:
Hayden 2022-12-31 16:57:30 -09:00
parent 25e01d9606
commit 59ebf0af73
No known key found for this signature in database
GPG key ID: 17CF79474E257545
4 changed files with 56 additions and 21 deletions

View file

@ -5,18 +5,21 @@
<script setup lang="ts">
type DateTimeFormat = "relative" | "long" | "short" | "human";
const props = defineProps({
date: {
type: [Date, String],
required: true,
},
format: {
type: String as () => DateTimeFormat,
default: "relative",
},
type Props = {
date?: Date | string;
format?: DateTimeFormat;
};
const props = withDefaults(defineProps<Props>(), {
date: undefined,
format: "relative",
});
const value = computed(() => {
if (!props.date || !validDate(props.date)) {
return "";
}
return fmtDate(props.date, props.format);
});
</script>