-1

I am trying out the FullCalendar 3.9.0 in Salesforce lightning component, when I pass the standard salesforce start and end date it displays on the Calendar in the lightning component but either the moment of fullcalendar js messes it and for example 10.9 being 10th September is being placed in 9th October box. Is there some issue why the plugin changes the Month and day like so?

Any days above 12 dont show obviously. Anyone else experience this?

ADyson
  • 57,178
  • 14
  • 51
  • 63

1 Answers1

1

It seems like you have a date format issue. It sounds as though you are supplying dates as strings in dd.mm.yyyy format (or something similar) but the browser is interpreting it as mm.dd.yyyy. You may even be seeing a warning in the browser console which relates to this.

If you send the date as a string the browser has no way to know whether you meant 10th Sept or 9th Oct, so it just has to guess.

Background: some cultures (e.g. UK and much of Europe) use dd.mm.yyyy, some use mm.dd.yyyy (e.g. USA) to present dates (to human beings), some use something else again. There's variation in the order of the elements, the separators used, and the conventions for when to use particular formats in different situations. As you've now learned, it's a bad idea to tie your data to one of these idiosyncratic formats. Computers cannot guess which culture you are intending to represent with your data.

Whilst it's certainly possible to tell the browser how to correctly interpret your ambiguous date, the simple, foolproof solution to this is not to use ambiguous date formats to begin with. Instead, use a non-ambiguous date format such as ISO 8601 - i.e. basically yyyy-mm-dd (for the date part).

ADyson
  • 57,178
  • 14
  • 51
  • 63
  • Hi I was thinking the same which is why I was trying to format it in said form as looking at the js the toDate to parsing it in dd.mm.yyyy, the sObject I am using is throwing an error if I try to format it as it is sent to the lightning component as a response but true it is passed in the end as a json so if I just send the sObject back as a string it should work. I was using majority of the example provided by the fullcalendar.io salesforce but can rewrite to resolve this. Thanks for the reply – Matthew Fitzsimons Sep 23 '19 at 17:43
  • I managed to fix it by taking the moment js in the format of the Salesforce apex in essence syncing and below to resolve e.StartDateTime= new Moment(String.valueOf(e.StartDateTime),'YYYY-dd-MM HH:mm:ss').toDatetime(); Moment apex i found from here https://github.com/Click-to-Cloud/Moment.apex/blob/master/src/classes/Moment.cls – Matthew Fitzsimons Sep 23 '19 at 20:01