From a007e0746eb02da4338fc9f37f3223da6e1dde92 Mon Sep 17 00:00:00 2001 From: Darshan Date: Sun, 18 May 2025 19:14:20 +0530 Subject: [PATCH] fix: date logic. --- src/routes/(console)/bottomAlerts.ts | 31 ++++++++-------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/src/routes/(console)/bottomAlerts.ts b/src/routes/(console)/bottomAlerts.ts index 8bc5a7c92..7cc9ce36c 100644 --- a/src/routes/(console)/bottomAlerts.ts +++ b/src/routes/(console)/bottomAlerts.ts @@ -10,6 +10,7 @@ import { showBottomModalAlert } from '$lib/stores/bottom-alerts'; import { isCloud } from '$lib/system'; +import { isSameDay } from '$lib/helpers/date'; const listOfPromotions: BottomModalAlertItem[] = []; @@ -118,28 +119,14 @@ export function addBottomModalAlerts() { listOfPromotions.forEach((promotion) => showBottomModalAlert(promotion)); } -function isPromoLive(date: string, time: string, timeZone: string = 'Europe/Paris'): boolean { - const isoString = `${date}T${time}:00`; - - const formatter = new Intl.DateTimeFormat('en', { - timeZone, - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit', - hourCycle: 'h23' - }); - - const parts = formatter.formatToParts(new Date(isoString)); - const map = Object.fromEntries( - parts.filter((p) => p.type !== 'literal').map((p) => [p.type, p.value]) - ); - - const target = new Date(`${map.year}-${map.month}-${map.day}T${map.hour}:${map.minute}:00`); - +export function isPromoLive( + date: string, + time: string, + timeZone: string = 'Asia/Kolkata' +): boolean { const now = new Date(); - const isSameDay = now.toISOString().slice(0, 10) === target.toISOString().slice(0, 10); + const targetString = `${date}T${time}:00`; + const target = new Date(new Date(targetString).toLocaleString('en-US', { timeZone })); - return isSameDay && now >= target; + return isSameDay(now, target) && now >= target; }