Question

I am trying to fetch the google calendar events on my site, and have successfully implemented it. But when I checked it for SAFARI, it was showing NaN for Date and undefined for month. Below is my code, I just pasted my whole copy of code.

I am editing my question as I have found the issue: So below was the issue and the fix is in the answer.

 for (var i = 0; i < eventArray.length; i++) {
    startDate = eventArray[i].start.date || eventArray[i].start.dateTime;
    endDate = eventArray[i].end.date || eventArray[i].end.dateTime;
    summary = eventArray[i].summary;
    description = eventArray[i].description;
    htmlLink = eventArray[i].htmlLink;
    event_location = eventArray[i].location;
    eventStartDate = new Date(startDate);
    eventEndDate = new Date(endDate);
    var isExist=false;
Was it helpful?

Solution 2

Here is the answer:

     for (var i = 0; i < eventArray.length; i++) {
        startDate = eventArray[i].start.date || eventArray[i].start.dateTime;
        endDate = eventArray[i].end.date || eventArray[i].end.dateTime;
        summary = eventArray[i].summary;
        description = eventArray[i].description;
        htmlLink = eventArray[i].htmlLink;
        event_location = eventArray[i].location;

/*For safari, we have to take out date, month and year individually, as I was getting date in startDate, so I parted it and went ahead */

    var parts = startDate.match(/(\d+)/g);
    eventStartDate = new Date(parts[0], parts[1]-1, parts[2])

/** Here was Invalid date issue for Safari which I was facing earlier eventStartDate = new Date(startDate); **/

OTHER TIPS

You have one problem here by the looks of it.

function getDateLowerLimit() {
    var todayDate;
    if (dateLowerlimit == "") {
        todayDate = new Date();
        dateLowerlimit = todayDate.getFullYear() + "-" + (todayDate.getMonth() < 10 ? '0' : '') + (todayDate.getMonth() + 1) + "-" + (todayDate.getDate() < 10 ? '0' : '') + todayDate.getDate() + "T00:00:00+00:00"
    } else {
        todayDate = new Date(dateLowerlimit)
    }
}

If dateLowerlimit is not an empty string then todayDate gets set within the scope of the function but it is never returned or used.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top