fix: display finance records and ledgers in Beijing time
Deploy olons-server production / deploy (push) Successful in 34s

This commit is contained in:
richjohnrambo
2026-10-23 00:13:07 +08:00
parent 8ce67648b1
commit f56b84bb10
9 changed files with 224 additions and 30 deletions
+6 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { dateTime } from './api';
import { dateTime, dateTimeSeconds } from './api';
describe('Beijing business time display', () => {
it.each(['UTC', 'America/New_York', 'Asia/Shanghai'])(
@@ -11,6 +11,9 @@ describe('Beijing business time display', () => {
expect(dateTime('2026-10-22T13:06:00Z')).toBe('2026-10-22 21:06');
expect(dateTime('2026-10-22T21:06:00+08:00')).toBe('2026-10-22 21:06');
expect(dateTime('2026-10-22T16:00:00Z')).toBe('2026-10-23 00:00');
expect(dateTimeSeconds('2026-10-22T13:06:07Z')).toBe('2026-10-22 21:06:07');
expect(dateTimeSeconds('2026-10-22T21:06:07+08:00')).toBe('2026-10-22 21:06:07');
expect(dateTimeSeconds('2026-10-22T16:00:07Z')).toBe('2026-10-23 00:00:07');
} finally {
if (previous === undefined) delete process.env.TZ;
else process.env.TZ = previous;
@@ -21,5 +24,7 @@ describe('Beijing business time display', () => {
it('uses a placeholder for missing or invalid timestamps', () => {
expect(dateTime()).toBe('--');
expect(dateTime('invalid-time')).toBe('--');
expect(dateTimeSeconds()).toBe('--');
expect(dateTimeSeconds('invalid-time')).toBe('--');
});
});
+9
View File
@@ -180,6 +180,14 @@ export function money(value?: number, currency = 'CNY') {
}
export function dateTime(value?: string) {
return formatBeijingDateTime(value, false);
}
export function dateTimeSeconds(value?: string) {
return formatBeijingDateTime(value, true);
}
function formatBeijingDateTime(value: string | undefined, withSeconds: boolean) {
if (!value) return '--';
const date = new Date(value);
if (Number.isNaN(date.getTime())) return '--';
@@ -190,6 +198,7 @@ export function dateTime(value?: string) {
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
...(withSeconds ? { second: '2-digit' as const } : {}),
hourCycle: 'h23',
})
.format(date)
+1 -17
View File
@@ -38,7 +38,7 @@
import { onMounted, ref } from 'vue';
import PageHeader from '../components/PageHeader.vue';
import AsyncState from '../components/AsyncState.vue';
import { errorText, request } from '../api';
import { dateTimeSeconds, errorText, request } from '../api';
type Direction = 'all' | 'income' | 'expense';
const tabs: Array<{ label: string; value: Direction }> = [
@@ -64,22 +64,6 @@
const plainMoney = (value: number) => (Number(value || 0) / 100).toFixed(2);
const entryText = (value: string) => entryLabels[value] || '账户余额变动';
function dateTimeSeconds(value?: string) {
if (!value) return '--';
const date = new Date(value);
if (Number.isNaN(date.getTime())) return '--';
return new Intl.DateTimeFormat('zh-CN', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false,
})
.format(date)
.replaceAll('/', '-');
}
async function load() {
loading.value = true;
error.value = '';