react-native-calendar-events
react-native-calendar-events copied to clipboard
Ios Event Date Time wrong and confused
I have an iOS device with CDT(GMT-5) timezone. An I created a date with time in 13:00 and with EDT(GMT-4) timezone. Expected hour in calendar: 12AM. Obtained:
Environment
React Native 0.64.2 react-native-calendar-events: 2.2.0
Steps to Reproduce
const dateStr = date.format('YYYY-MM-DD HH:mm:ss');
const localOffset = moment().utcOffset() / 60;
const offset = addLeadingZeros(timeZoneCalendar, 2);
const offsetLocal = addLeadingZeros(localOffset, 2);
const momentDate = moment(dateStr, 'YYYY-MM-DD HH:mm:ss').utcOffset(
offset,
true
);
const utcDate = momentDate.utc().format('YYYY-MM-DD HH:mm:ss');
const dateWithFinalUTC =
moment(utcDate, 'YYYY-MM-DDTHH:mm:ss.SSS[Z]')
.add(offsetLocal, 'h')
.format('YYYY-MM-DDTHH:mm:ss.SSSZ');
Expected Behavior
Like android behavior, set the ISO string with correct time.
Actual Behavior
Wrong date, this sceneries not happen in Android
Do it like this
change it according to your need `const Match_time = (new Date(Item.Date_Time).getTime() - 1200000); const Match_Time_Before_20_Min = new Date(Match_time);
const TimeAfter_1_Hr = (new Date(Item.Date_Time).getTime() + 2400000);
const TimeDate_After_40_Min = new Date(TimeAfter_1_Hr);
await RNCalendarEvents.saveEvent(`Your ${Item.Game_Name} Match is about to start in 15 Minutes`, {
startDate: Match_Time_Before_20_Min.toISOString(),
endDate: TimeDate_After_40_Min.toISOString(),
})`