I am using this function to parse wall time of future event to user local timezone:
export const parseGatheringDate = (
timeZone: string,
gatheringData: {
date: string;
time: string;
timeZone: string;
}
) => {
const eventDateTime = `${gatheringData.date}T${gatheringData.time}:00`;
const gathering = dayjs.tz(eventDateTime, gatheringData.timeZone);
const eventInLocalTime = gathering.tz(timeZone);
const formattedEventTime = eventInLocalTime.format("YYYY-MM-DD HH:mm");
return formattedEventTime;
};
And on web I am getting:
2024-08-21 02:00
2024-08-21 08:00
Which are correct values.
But on IOS simulator in react-native for the same code I am getting:
2024-08-21 06:44
2024-08-21 06:44
Test code is:
console.log(
"DATE 1",
parseGatheringDate("Europe/Belgrade", {
date: "2024-08-21",
time: "08:00",
timeZone: "Europe/Belgrade",
})
);
console.log(
"DATE 2",
parseGatheringDate("America/New_York", {
date: "2024-08-21",
time: "08:00",
timeZone: "Europe/Belgrade",
})
);