From 1acb80e4e769bc9eebd557a19e90b71530bed7d3 Mon Sep 17 00:00:00 2001 From: dmouriss Date: Thu, 31 Aug 2023 22:23:37 +0200 Subject: [PATCH 1/2] Fix buildFromDateId function --- client/src/services/stats.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/client/src/services/stats.ts b/client/src/services/stats.ts index d85b232a..45022db2 100644 --- a/client/src/services/stats.ts +++ b/client/src/services/stats.ts @@ -14,11 +14,9 @@ export const fresh = (d: Date, eraseHour = false) => { }; export const buildFromDateId = (dateId: DateId) => { - const date = fresh(new Date()); - date.setFullYear(dateId.year); - date.setMonth((dateId.month ?? 1) - 1); - date.setDate(dateId.day ?? 1); - date.setHours(dateId.hour ?? 0); + const date = fresh( + new Date(dateId.year, dateId.month ?? 1, dateId.day ?? 1, dateId.hour ?? 0), + ); return date; }; From 9128bd55df6b559f4aaf33ddf361d566b7cb8f99 Mon Sep 17 00:00:00 2001 From: dmouriss Date: Thu, 31 Aug 2023 22:55:23 +0200 Subject: [PATCH 2/2] Fix month offset --- client/src/services/stats.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/client/src/services/stats.ts b/client/src/services/stats.ts index 45022db2..0ab5934e 100644 --- a/client/src/services/stats.ts +++ b/client/src/services/stats.ts @@ -15,7 +15,12 @@ export const fresh = (d: Date, eraseHour = false) => { export const buildFromDateId = (dateId: DateId) => { const date = fresh( - new Date(dateId.year, dateId.month ?? 1, dateId.day ?? 1, dateId.hour ?? 0), + new Date( + dateId.year, + (dateId.month ?? 1) - 1, + dateId.day ?? 1, + dateId.hour ?? 0, + ), ); return date; };