Revert "Use dayjs for UI datetime"

This commit is contained in:
Natsumi
2025-10-09 06:02:56 +13:00
parent c1ce4d9557
commit 2832539afa
+44 -20
View File
@@ -1,4 +1,3 @@
import dayjs from 'dayjs';
import { useAppearanceSettingsStore } from '../../../stores'; import { useAppearanceSettingsStore } from '../../../stores';
/** /**
@@ -18,36 +17,61 @@ function formatDateFilter(dateStr, format) {
return '-'; return '-';
} }
const dt = dayjs(dateStr); const dt = new Date(dateStr);
if (!dt.isValid()) { if (isNaN(dt.getTime())) {
return '-'; return '-';
} }
function padZero(num) {
return String(num).padStart(2, '0');
}
function toIsoLong(date) { function toIsoLong(date) {
return date.format('YYYY-MM-DD HH:mm:ss'); const y = date.getFullYear();
const m = padZero(date.getMonth() + 1);
const d = padZero(date.getDate());
const hh = padZero(date.getHours());
const mm = padZero(date.getMinutes());
const ss = padZero(date.getSeconds());
return `${y}-${m}-${d} ${hh}:${mm}:${ss}`;
} }
function toLocalShort(date) { function toLocalShort(date) {
// Use localized format for short date return date
let fmt = 'MM/DD HH:mm'; .toLocaleDateString(isoFormat ? 'en-nz' : currentCulture, {
if (!isoFormat) { month: '2-digit',
fmt = hour12 ? 'L LT' : 'L HH:mm'; day: '2-digit',
} hour: 'numeric',
let str = date.locale(currentCulture).format(fmt); minute: 'numeric',
// Lowercase AM/PM hourCycle: hour12 ? 'h12' : 'h23'
str = str.replace(' AM', 'am').replace(' PM', 'pm').replace(',', ''); })
return str; .replace(' AM', 'am')
.replace(' PM', 'pm')
.replace(',', '');
} }
if (format === 'long') { if (isoFormat) {
if (isoFormat) { if (format === 'long') {
return toIsoLong(dt); return toIsoLong(dt);
} }
const fmt = hour12 ? 'L LTS' : 'L HH:mm:ss'; if (format === 'short') {
return dt.locale(currentCulture).format(fmt); return toLocalShort(dt);
} }
if (format === 'short') { } else {
return toLocalShort(dt); if (format === 'long') {
return dt.toLocaleDateString(currentCulture, {
month: '2-digit',
day: '2-digit',
year: 'numeric',
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
hourCycle: hour12 ? 'h12' : 'h23'
});
}
if (format === 'short') {
return toLocalShort(dt);
}
} }
return '-'; return '-';