forked from FoundKeyGang/FoundKey
Merge pull request 'Fix birthday time offset and date locale' (#66) from fix/date into main
Reviewed-on: FoundKeyGang/FoundKey#66
This commit is contained in:
commit
bb073670ef
2 changed files with 8 additions and 4 deletions
|
@ -9,22 +9,26 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { onUnmounted } from 'vue';
|
import { onUnmounted } from 'vue';
|
||||||
import { i18n } from '@/i18n';
|
import { i18n } from '@/i18n';
|
||||||
|
import { lang } from '@/config';
|
||||||
|
|
||||||
const props = withDefaults(defineProps<{
|
const props = withDefaults(defineProps<{
|
||||||
time: Date | string;
|
time: Date | string;
|
||||||
format?: 'both' | 'date' | 'time';
|
format?: 'both' | 'date' | 'time';
|
||||||
mode?: 'relative' | 'absolute' | 'detail';
|
mode?: 'relative' | 'absolute' | 'detail';
|
||||||
|
utc?: boolean;
|
||||||
}>(), {
|
}>(), {
|
||||||
format: 'both',
|
format: 'both',
|
||||||
mode: 'relative',
|
mode: 'relative',
|
||||||
|
utc: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const _time = typeof props.time === 'string' ? new Date(props.time) : props.time;
|
const _time = typeof props.time === 'string' ? new Date(props.time) : props.time;
|
||||||
const absolute = ((): string => {
|
const absolute = ((): string => {
|
||||||
|
const options = props.utc ? { timeZone: 'UTC' } : {};
|
||||||
switch (props.format) {
|
switch (props.format) {
|
||||||
case 'date': return _time.toLocaleDateString();
|
case 'date': return _time.toLocaleDateString(lang ?? 'en-US', options);
|
||||||
case 'time': return _time.toLocaleTimeString();
|
case 'time': return _time.toLocaleTimeString(lang ?? 'en-US', options);
|
||||||
default: return _time.toLocaleString();
|
default: return _time.toLocaleString(lang ?? 'en-US', options);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@
|
||||||
</dl>
|
</dl>
|
||||||
<dl v-if="user.birthday" class="field">
|
<dl v-if="user.birthday" class="field">
|
||||||
<dt class="name"><i class="fas fa-birthday-cake fa-fw"></i> {{ i18n.ts.birthday }}</dt>
|
<dt class="name"><i class="fas fa-birthday-cake fa-fw"></i> {{ i18n.ts.birthday }}</dt>
|
||||||
<dd class="value"><MkTime format="date" mode="detail" :time="user.birthday"/></dd>
|
<dd class="value"><MkTime format="date" mode="detail" :time="user.birthday" :utc="true"/></dd>
|
||||||
</dl>
|
</dl>
|
||||||
<dl class="field">
|
<dl class="field">
|
||||||
<dt class="name"><i class="fas fa-calendar-alt fa-fw"></i> {{ i18n.ts.registeredDate }}</dt>
|
<dt class="name"><i class="fas fa-calendar-alt fa-fw"></i> {{ i18n.ts.registeredDate }}</dt>
|
||||||
|
|
Loading…
Reference in a new issue