From 6bc88466a37bd60aa58a784ebf4cd2dd9842c269 Mon Sep 17 00:00:00 2001 From: Kevin McConnell Date: Thu, 23 Jan 2025 12:45:02 +0000 Subject: [PATCH] Only highlight current hour on today's entry --- app/javascript/controllers/timeline_controller.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/javascript/controllers/timeline_controller.js b/app/javascript/controllers/timeline_controller.js index 9dfccc63e..d7ca0638d 100644 --- a/app/javascript/controllers/timeline_controller.js +++ b/app/javascript/controllers/timeline_controller.js @@ -20,15 +20,17 @@ export default class extends Controller { #dateIsToday(dt) { const date = new Date(this.dateValue) - return dt.getYear() == date.getYear() && - dt.getMonth() == date.getMonth() && - dt.getDay() == date.getDay() + return this.#sameDay(dt, date) } #isCurrentHour(dt) { const now = new Date() - const utcHour = dt.getUTCHours() - const localHour = now.getHours() - return utcHour === localHour + return this.#sameDay(dt, now) && dt.getHours() === now.getHours() + } + + #sameDay(dt1, dt2) { + return dt1.getYear() === dt2.getYear() && + dt1.getMonth() === dt2.getMonth() && + dt1.getDay() === dt2.getDay() } }