From aed45ed1bb98fa8fbb4c82b54ffa07a16b027a99 Mon Sep 17 00:00:00 2001 From: Cory Dransfeldt Date: Wed, 1 Nov 2023 09:27:30 -0700 Subject: [PATCH] fix: account for am/pm --- netlify/edge-functions/now-playing.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/netlify/edge-functions/now-playing.js b/netlify/edge-functions/now-playing.js index 443e1e78..4703c4db 100644 --- a/netlify/edge-functions/now-playing.js +++ b/netlify/edge-functions/now-playing.js @@ -106,11 +106,16 @@ export default async () => { const endTime = new Date(endDate).toLocaleString('en-US', { timeZone: 'America/Los_Angeles', }) - const now = new Date().toLocaleString('en-US', { + const nowDate = new Date() + const now = nowDate.toLocaleString('en-US', { timeZone: 'America/Los_Angeles', }) + const startAmPm = startDate.getHours() >= 12 ? 'pm' : 'am' + const nowAmPm = nowDate.getHours() >= 12 ? 'pm' : 'am' const isCorrectDate = - now.split(',')[0] === startTime.split(',')[0] && now.split(',')[0] === endTime.split(',')[0] + now.split(',')[0] === startTime.split(',')[0] && + now.split(',')[0] === endTime.split(',')[0] && + startAmPm === nowAmPm const nowHour = parseInt(now.split(',')[1].split(':')[0].trim()) const startHour = parseInt(startTime.split(',')[1].split(':')[0].trim()) const endHour = parseInt(endTime.split(',')[1].split(':')[0].trim())