From bbc056d4c38e2fc71d65875212225fdb5603c3cf Mon Sep 17 00:00:00 2001 From: suvarnakale Date: Fri, 13 Dec 2024 18:33:48 +0530 Subject: [PATCH] Issue #PS-2758 chore: calender time zone issue solved --- src/hooks/useEventDates.js | 9 +++++++-- src/utils/Helper.ts | 13 +++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/hooks/useEventDates.js b/src/hooks/useEventDates.js index 12e8d7be..1a820681 100644 --- a/src/hooks/useEventDates.js +++ b/src/hooks/useEventDates.js @@ -1,6 +1,11 @@ import { useEffect, useState } from 'react'; import { getEventList } from '@/services/EventService'; -import { shortDateFormat, getAfterDate, getBeforeDate } from '../utils/Helper'; +import { + shortDateFormat, + getAfterDate, + getBeforeDate, + convertToIST, +} from '../utils/Helper'; import { dashboardDaysLimit } from '../../app.config'; const useEventDates = ( @@ -67,7 +72,7 @@ const useEventDates = ( if (response?.events?.length > 0) { response.events.forEach((event) => { if (event.startDateTime) { - const eventDate = event.startDateTime.slice(0, 10); + const eventDate = convertToIST(event.startDateTime); newEventDates[eventDate] = { event: true }; } }); diff --git a/src/utils/Helper.ts b/src/utils/Helper.ts index ddb43e6c..e1556298 100644 --- a/src/utils/Helper.ts +++ b/src/utils/Helper.ts @@ -369,6 +369,19 @@ export const convertUTCToIST = (utcDateTime: string) => { return { date: formattedDate, time: formattedTime }; }; +export const convertToIST = (utcDate: string | number | Date) => { + const date = new Date(utcDate); + const options: Intl.DateTimeFormatOptions = { + timeZone: 'Asia/Kolkata', + year: 'numeric', + month: '2-digit', + day: '2-digit', + }; + const istDate = date.toLocaleString('en-GB', options); + const [day, month, year] = istDate.split('/'); + return `${year}-${month}-${day}`; +}; + export const convertLocalToUTC = (localDateTime: any) => { const localDate = new Date(localDateTime); const utcDateTime = localDate.toISOString();