We are using FullCalendar.io library to our Salesforce LWC component. I am using timeZone = 'local'.
When returning the events from Server, browser inspector shows proper data, but when we open 'Fullcalendar' it displays wrong time on client side. It doubles the GMT value.
E.g Event StartTime from server = 12:00 but when I convert it to GMT+1 it converts it to 14:00 instead of 13:00. Ideally it should only add 1 hour as per GMT+1, but it adds 2 hours.
For India Case where timezone = GMT+5:30, it adds 11 hours instead of 5:30. Please share your thoughts?
Here is the code:
@wire(fetchEvents)
eventObj(value){
this.eventOriginalData = value; //To use in refresh cache
///////
const {data, error} = value;
if(data){
//format as fullcalendar event object
let events = data.map(event => {
var sttime = new Date(event.StartDateTime);
var etime = new Date(event.EndDateTime);
var formattedStartTime = sttime.toString();
var formattedEndTime = etime.toString();
return { id : event.Id,
title : event.Subject,
start : formattedStartTime,
end : formattedEndTime};
});
this.events = JSON.parse(JSON.stringify(events));
console.log(this.events);
this.error = undefined;
//load only on first wire call -
// if events are not rendered, try to remove this 'if' condition and add directly
if(! this.eventsRendered){
//Add events to calendar
const ele = this.template.querySelector("div.fullcalendarjs");
$(ele).fullCalendar('renderEvents', this.events, true);
this.eventsRendered = true;
}
}else if(error){
this.events = [];
this.error = 'No events are found';
}
}
event.StartDateTime = 2022-12-07T12:00:00.000+0000 (Comming from Salesforce) event.EndDateTime = 2022-12-07T13:00:00.000+0000 (Comming from Salesforce)
My TimeZone from where I open fullCalendar is GMT +1.
Tried with many different config. e.g toUTCString(). but still either it displays Server Original Date, or it converts and adds GMT double value.