From 1623500a48ea967f5ae01c280024633e87ef1076 Mon Sep 17 00:00:00 2001 From: t0ng7u Date: Thu, 1 Jan 2026 13:55:23 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(dashboard):=20include=20year?= =?UTF-8?q?=20in=20time=20bucket=20labels=20to=20fix=20cross-year=20orderi?= =?UTF-8?q?ng?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ensure dashboard time buckets sort correctly across year boundaries by including the year in `timestamp2string1()` output. Previously, labels like `MM-DD` / `MM-DD HH:00` could be string-sorted into the wrong order (e.g. `01-01` before `12-31`), making it look like the new year’s data was missing or the timeline was “reversed”. Changes: - Update `timestamp2string1()` to emit sortable keys: - hour: `YYYY-MM-DD HH:00` - day: `YYYY-MM-DD` - week: `YYYY-MM-DD - YYYY-MM-DD` (both ends include year) --- web/src/helpers/utils.jsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/web/src/helpers/utils.jsx b/web/src/helpers/utils.jsx index 0cbdebd15..bfe9bed7d 100644 --- a/web/src/helpers/utils.jsx +++ b/web/src/helpers/utils.jsx @@ -219,7 +219,7 @@ export function timestamp2string(timestamp) { export function timestamp2string1(timestamp, dataExportDefaultTime = 'hour') { let date = new Date(timestamp * 1000); - // let year = date.getFullYear().toString(); + let year = date.getFullYear().toString(); let month = (date.getMonth() + 1).toString(); let day = date.getDate().toString(); let hour = date.getHours().toString(); @@ -235,11 +235,12 @@ export function timestamp2string1(timestamp, dataExportDefaultTime = 'hour') { if (hour.length === 1) { hour = '0' + hour; } - let str = month + '-' + day; + let str = year + '-' + month + '-' + day; if (dataExportDefaultTime === 'hour') { str += ' ' + hour + ':00'; } else if (dataExportDefaultTime === 'week') { let nextWeek = new Date(timestamp * 1000 + 6 * 24 * 60 * 60 * 1000); + let nextYear = nextWeek.getFullYear().toString(); let nextMonth = (nextWeek.getMonth() + 1).toString(); let nextDay = nextWeek.getDate().toString(); if (nextMonth.length === 1) { @@ -248,7 +249,7 @@ export function timestamp2string1(timestamp, dataExportDefaultTime = 'hour') { if (nextDay.length === 1) { nextDay = '0' + nextDay; } - str += ' - ' + nextMonth + '-' + nextDay; + str += ' - ' + nextYear + '-' + nextMonth + '-' + nextDay; } return str; }