Skip to content

Commit

Permalink
Merge pull request #520 from suvarnakale/release-1.0.0
Browse files Browse the repository at this point in the history
Issue #PS-2758 chore: calender time zone issue solved
  • Loading branch information
itsvick authored Dec 13, 2024
2 parents 181658e + bbc056d commit 8921e45
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/hooks/useEventDates.js
Original file line number Diff line number Diff line change
@@ -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 = (
Expand Down Expand Up @@ -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 };
}
});
Expand Down
13 changes: 13 additions & 0 deletions src/utils/Helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 8921e45

Please sign in to comment.