fix(timezone): 修复数据写入时的时区错误(关键修复)

- 修复 redis.js 中所有时区相关的日期获取方法
  - 使用 getUTC* 方法替代 get* 方法获取正确的时区日期
  - 影响:incrementTokenUsage, incrementAccountUsage, incrementDailyCost 等
- 修复 admin.js 中查询数据时的日期键生成
- 确保所有 Redis 键格式一致:
  - 日期:YYYY-MM-DD
  - 月份:YYYY-MM
  - 小时:YYYY-MM-DD:HH
- 添加服务端时间标签,避免前端时区转换问题

这是核心修复,确保数据从源头就是正确的。
This commit is contained in:
shaw
2025-07-30 10:07:25 +08:00
parent 5503004b66
commit 4c64e6df4b
5 changed files with 56 additions and 27 deletions

View File

@@ -444,6 +444,11 @@ function createUsageTrendChart() {
// 根据数据类型确定标签字段和格式
const labelField = data[0]?.date ? 'date' : 'hour'
const labels = data.map(d => {
// 优先使用后端提供的label字段
if (d.label) {
return d.label
}
if (labelField === 'hour') {
// 格式化小时显示
const date = new Date(d.hour)
@@ -655,6 +660,11 @@ function createApiKeysUsageTrendChart() {
const chartData = {
labels: data.map(d => {
// 优先使用后端提供的label字段
if (d.label) {
return d.label
}
if (labelField === 'hour') {
// 格式化小时显示
const date = new Date(d.hour)