forked from FoundKeyGang/FoundKey
Fix birthday time offset and date locale
The user's configred birthday is stored as UTC time, so use that for display as well. This means the birthday won't be shown as a day behind or ahead depending on the user's browser timezone. Also use the locale configured in the user's client settings in Misskey for date formatting.
This commit is contained in:
parent
a07b464690
commit
1cb5856f7c
2 changed files with 8 additions and 4 deletions
|
@ -9,22 +9,26 @@
|
|||
<script lang="ts" setup>
|
||||
import { onUnmounted } from 'vue';
|
||||
import { i18n } from '@/i18n';
|
||||
import { lang } from '@/config';
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
time: Date | string;
|
||||
format?: 'both' | 'date' | 'time';
|
||||
mode?: 'relative' | 'absolute' | 'detail';
|
||||
utc?: boolean;
|
||||
}>(), {
|
||||
format: 'both',
|
||||
mode: 'relative',
|
||||
utc: false,
|
||||
});
|
||||
|
||||
const _time = typeof props.time === 'string' ? new Date(props.time) : props.time;
|
||||
const absolute = ((): string => {
|
||||
const options = props.utc ? { timeZone: 'UTC' } : {};
|
||||
switch (props.format) {
|
||||
case 'date': return _time.toLocaleDateString();
|
||||
case 'time': return _time.toLocaleTimeString();
|
||||
default: return _time.toLocaleString();
|
||||
case 'date': return _time.toLocaleDateString(lang ?? 'en-US', options);
|
||||
case 'time': return _time.toLocaleTimeString(lang ?? 'en-US', options);
|
||||
default: return _time.toLocaleString(lang ?? 'en-US', options);
|
||||
}
|
||||
})();
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
</dl>
|
||||
<dl v-if="user.birthday" class="field">
|
||||
<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 class="field">
|
||||
<dt class="name"><i class="fas fa-calendar-alt fa-fw"></i> {{ i18n.ts.registeredDate }}</dt>
|
||||
|
|
Loading…
Reference in a new issue