mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 09:20:22 +08:00
fix(dashboard): 修复今日统计口径并对齐每日统计日期显示
- 前端请求 /api/dashboard/stats 时传递 timezone 和 tz_offset_minutes - 后端仪表盘汇总过滤 pending/streaming 和占位 provider,修正今日请求/Token/费用统计 - 今日 Token 卡片增加 K/M 单位显示,并补充写缓存/读缓存 Token 信息 - 修复每日统计 YYYY-MM-DD 被按 UTC 解析导致的“今天/昨天”串天问题 - 补充前后端回归测试,覆盖统计口径和日期解析场景
This commit is contained in:
19
frontend/src/utils/__tests__/date.spec.ts
Normal file
19
frontend/src/utils/__tests__/date.spec.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { parseDateLike } from '../date'
|
||||
|
||||
describe('parseDateLike', () => {
|
||||
it('parses date-only strings as local calendar dates', () => {
|
||||
const date = parseDateLike('2026-04-12')
|
||||
|
||||
expect(date.getFullYear()).toBe(2026)
|
||||
expect(date.getMonth()).toBe(3)
|
||||
expect(date.getDate()).toBe(12)
|
||||
})
|
||||
|
||||
it('keeps timestamp strings delegated to native Date parsing', () => {
|
||||
const date = parseDateLike('2026-04-12T15:30:00Z')
|
||||
|
||||
expect(Number.isNaN(date.getTime())).toBe(false)
|
||||
expect(date.toISOString()).toBe('2026-04-12T15:30:00.000Z')
|
||||
})
|
||||
})
|
||||
15
frontend/src/utils/date.ts
Normal file
15
frontend/src/utils/date.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
const DATE_ONLY_PATTERN = /^(\d{4})-(\d{2})-(\d{2})$/
|
||||
|
||||
/**
|
||||
* 将 `YYYY-MM-DD` 解析为本地时区日期,避免浏览器按 UTC 解析后串天。
|
||||
* 其他带时间/时区的信息仍交给原生 Date 处理。
|
||||
*/
|
||||
export function parseDateLike(dateString: string): Date {
|
||||
const matched = DATE_ONLY_PATTERN.exec(dateString)
|
||||
if (!matched) {
|
||||
return new Date(dateString)
|
||||
}
|
||||
|
||||
const [, year, month, day] = matched
|
||||
return new Date(Number(year), Number(month) - 1, Number(day))
|
||||
}
|
||||
Reference in New Issue
Block a user