refactor: show time
This commit is contained in:
parent
6b688477f1
commit
1e2aeb0afb
2 changed files with 29 additions and 7 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
// NOTE: Import stores
|
// NOTE: Import stores
|
||||||
import { dateFormat } from 'src/utils/datetime';
|
import { dateFormatJS } from 'src/utils/datetime';
|
||||||
|
|
||||||
// NOTE Import Types
|
// NOTE Import Types
|
||||||
import {
|
import {
|
||||||
|
|
@ -96,7 +96,11 @@ defineProps<{
|
||||||
:label="$t('taskOrder.workStartDate')"
|
:label="$t('taskOrder.workStartDate')"
|
||||||
>
|
>
|
||||||
<template #value>
|
<template #value>
|
||||||
{{ acceptedAt ? dateFormat(acceptedAt) : '-' }}
|
{{
|
||||||
|
acceptedAt
|
||||||
|
? dateFormatJS({ date: acceptedAt, withTime: true })
|
||||||
|
: '-'
|
||||||
|
}}
|
||||||
</template>
|
</template>
|
||||||
</DataDisplay>
|
</DataDisplay>
|
||||||
|
|
||||||
|
|
@ -105,7 +109,11 @@ defineProps<{
|
||||||
:label="$t('taskOrder.workSubmissionDate')"
|
:label="$t('taskOrder.workSubmissionDate')"
|
||||||
>
|
>
|
||||||
<template #value>
|
<template #value>
|
||||||
{{ submittedAt ? dateFormat(submittedAt) : '-' }}
|
{{
|
||||||
|
submittedAt
|
||||||
|
? dateFormatJS({ date: submittedAt, withTime: true })
|
||||||
|
: '-'
|
||||||
|
}}
|
||||||
</template>
|
</template>
|
||||||
</DataDisplay>
|
</DataDisplay>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,8 @@ export function dateFormatJS(opts: {
|
||||||
noDay?: boolean;
|
noDay?: boolean;
|
||||||
noMonth?: boolean;
|
noMonth?: boolean;
|
||||||
noYear?: boolean;
|
noYear?: boolean;
|
||||||
}) {
|
withTime?: boolean;
|
||||||
|
}): string {
|
||||||
const dt = opts.date ? new Date(opts.date) : new Date();
|
const dt = opts.date ? new Date(opts.date) : new Date();
|
||||||
|
|
||||||
const { locale } = i18n.global;
|
const { locale } = i18n.global;
|
||||||
|
|
@ -35,6 +36,17 @@ export function dateFormatJS(opts: {
|
||||||
opts.timeStyle = opts.timeStyle || 'short';
|
opts.timeStyle = opts.timeStyle || 'short';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let timeText = opts.withTime
|
||||||
|
? ' ' +
|
||||||
|
dateFormatJS({
|
||||||
|
date: opts.date,
|
||||||
|
timeOnly: true,
|
||||||
|
timeStyle: opts.timeStyle,
|
||||||
|
})
|
||||||
|
: '';
|
||||||
|
|
||||||
|
if (timeText) opts.timeStyle = undefined;
|
||||||
|
|
||||||
let formatted = new Intl.DateTimeFormat(opts.locale, {
|
let formatted = new Intl.DateTimeFormat(opts.locale, {
|
||||||
day: opts.noDay ? undefined : opts.dayStyle || 'numeric',
|
day: opts.noDay ? undefined : opts.dayStyle || 'numeric',
|
||||||
month: opts.noMonth ? undefined : opts.monthStyle || 'short',
|
month: opts.noMonth ? undefined : opts.monthStyle || 'short',
|
||||||
|
|
@ -46,11 +58,13 @@ export function dateFormatJS(opts: {
|
||||||
case Lang.Thai:
|
case Lang.Thai:
|
||||||
case 'th-TH':
|
case 'th-TH':
|
||||||
case 'th-Th':
|
case 'th-Th':
|
||||||
return formatted.replace(/(\d{4})/, (year) =>
|
return (
|
||||||
(parseInt(year) - 543).toString(),
|
formatted.replace(/(\d{4})/, (year) =>
|
||||||
|
(parseInt(year) - 543).toString(),
|
||||||
|
) + timeText
|
||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
return formatted;
|
return formatted + timeText;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue