fix: 修复账单时间显示为UTC时区问题,改为本地时间

- 新增 LocalTime 自定义类型,JSON序列化输出本地时间格式
- 修改 CleanedBill.Time 字段类型为 LocalTime
- 更新 parseTime 函数返回 LocalTime 类型
- 前端添加 formatDateTime 工具函数(兼容处理)
- 版本号更新至 1.0.2
This commit is contained in:
2026-01-11 21:40:27 +08:00
parent d49d9afb3a
commit 8a9de1b328
9 changed files with 107 additions and 14 deletions

View File

@@ -16,6 +16,31 @@ export function formatLocalDate(date: Date): string {
return `${y}-${m}-${d}`;
}
/**
* 将 ISO 时间字符串UTC转换为本地时区的格式化字符串
* 用于显示账单交易时间
* @param isoString - ISO 格式的时间字符串,如 "2026-01-10T05:12:13Z"
* @returns 本地时间格式,如 "2026-01-10 13:12:13"
*/
export function formatDateTime(isoString: string): string {
if (!isoString) return '';
try {
const date = new Date(isoString);
if (isNaN(date.getTime())) return isoString;
const y = date.getFullYear();
const m = String(date.getMonth() + 1).padStart(2, '0');
const d = String(date.getDate()).padStart(2, '0');
const h = String(date.getHours()).padStart(2, '0');
const min = String(date.getMinutes()).padStart(2, '0');
const s = String(date.getSeconds()).padStart(2, '0');
return `${y}-${m}-${d} ${h}:${min}:${s}`;
} catch {
return isoString;
}
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type WithoutChild<T> = T extends { child?: any } ? Omit<T, "child"> : T;
// eslint-disable-next-line @typescript-eslint/no-explicit-any

View File

@@ -12,7 +12,7 @@
import { Separator } from '$lib/components/ui/separator';
import { DateRangePicker } from '$lib/components/ui/date-range-picker';
import ManualBillInput from '$lib/components/bills/ManualBillInput.svelte';
import { formatLocalDate } from '$lib/utils';
import { formatLocalDate, formatDateTime } from '$lib/utils';
import Loader2 from '@lucide/svelte/icons/loader-2';
import AlertCircle from '@lucide/svelte/icons/alert-circle';
import Search from '@lucide/svelte/icons/search';
@@ -385,7 +385,7 @@
{#each displayRecords as record}
<Table.Row>
<Table.Cell class="text-muted-foreground text-sm">
{record.time}
{formatDateTime(record.time)}
</Table.Cell>
<Table.Cell class="hidden xl:table-cell">
<Badge variant={record.bill_type === 'manual' ? 'outline' : (record.bill_type === 'alipay' ? 'default' : 'secondary')}>