-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDate.vue
39 lines (35 loc) · 843 Bytes
/
Date.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<script setup lang="ts">
const props = defineProps({
/**
* { time, string }
*/
date: [Date, String],
textSize: {
type: String,
default: null,
},
})
const { t } = useI18n()
const dateObject = computed(() => {
const date = props.date instanceof Date ? props.date : new Date(props.date as string)
return {
time: +date,
string: date.toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric',
}),
}
})
const getDateTime = () => new Date().toISOString()
</script>
<template>
<dl>
<dt class="sr-only">
{{ t('posted_on') }}
</dt>
<dd class="font-medium leading-6 text-gray-500 dark:text-gray-400" :class="[textSize ? `text-${textSize}` : 'text-base']">
<time :datetime="getDateTime()">{{ dateObject.string }}</time>
</dd>
</dl>
</template>