FormatGoogleCalendar icon indicating copy to clipboard operation
FormatGoogleCalendar copied to clipboard

All day event

Open AlexVilla opened this issue 8 years ago • 14 comments

I don't know if that problem just happen to me, but when I see an all day event y see that the event start the previous day, just an example, if in google calendar I have an all day event for october 22, in the result of the script I have that the event is on october 21.

AlexVilla avatar Oct 22 '16 16:10 AlexVilla

I'm seeing the same thing.

greyhammer avatar Oct 26 '16 01:10 greyhammer

Actually I've made some changes to the plugin and translate to spanish, and I can fix that

AlexVilla avatar Oct 26 '16 01:10 AlexVilla

Hi guys. This might be related to fixes I did for the All Day Events display 2 Days #6 issue. There are several ways on how one can create an all day event in the Google calendar UI. Each of those ways is represented differently in the output JSON. Because of this inconsistency I probably overlooked something and you end up with this issue in some cases. There is also possibility that Google has changed the way how all day events are represented in the JSON output. As I look at my testing site, some of all day event dates get displayed in a different format than a month ago. Currently, I don't have resources to dedicate myself to the issue. Would be great if anyone else can take a look at that.

MilanLund avatar Oct 26 '16 12:10 MilanLund

I fix that, the first thing is that the all day event, at least to me, starts and ends at 21:00 and not at 00:00, and the other thing was changing the if on transformationList function for the isAllDayEvent and let just this line dateStart = dateEnd; @greyhammer try to do this and if this works for you and let us know.

if (isAllDayEvent) {
          dateStart = dateEnd;
        }

AlexVilla avatar Oct 26 '16 19:10 AlexVilla

I had the same issue. I added another function:

//Add one day
var addOneDay = function (dateInfo) {
     var date = getDateFormatted(dateInfo);
     date.setTime(date.getTime() + 86400000);
     return getDateInfo(date);
 };

And then changed the if for the moreDaysEvent

if (moreDaysEvent) {
     dateStart = addOneDay(dateStart);
}

AntoineT7 avatar Nov 17 '16 18:11 AntoineT7

@AntoineT7 I'm not seeing the if moreDaysEvent block anywhere. This is a troubling issue, as I'm using it to list upcoming events, and I can't have the days showing up incorrectly.

KennyStier avatar Dec 04 '16 20:12 KennyStier

Hey @19kestier, if you're using the latest version that's up (from 3 months ago), the moreDaysEvent starts at line 135.

I added the addOneDay function above the existing subtractOneDay function starting at line 219.

AntoineT7 avatar Dec 05 '16 16:12 AntoineT7

@AntoineT7, your fix works wonderfully! Please submit a pull request!

KennyStier avatar Dec 05 '16 21:12 KennyStier

@AntoineT7 @19kestier Could you please check whether "addOneDay" fix still works for you? I came back to check this repository after long time and I see that events that take more than one day start and end one day later in the rendered calendar.

This has fixed my issue: if (isAllDayEvent || moreDaysEvent) { dateEnd = subtractOneMinute(dateEnd); }

MilanLund avatar Feb 11 '17 09:02 MilanLund

My fix still works: https://millhousenchurch.com/js/format-google-calendar.js

KennyStier avatar Feb 13 '17 21:02 KennyStier

Sorry for the delay! This fix still works for me.

AntoineT7 avatar Feb 26 '17 21:02 AntoineT7

I am reopening the issue as I received a bug report for the same problem. There is also the theory behind that may be the cause: "The Google API on all-day-events have a start date with a UTC of 00:00:00 and since my time zone is -6, it comes through as the previous day. I tested my theory by changing my local time zone on my computer, when I am at UTC 0 time, the date on all-day-events displays correctly." It needs research and reasonable fix.

MilanLund avatar Jan 24 '18 12:01 MilanLund

Has anyone found an adequate fix for this?

gospellight avatar Feb 07 '18 16:02 gospellight

What I found via debugging, was that the startdate and enddates for All Day events reported from Google Calendar were in a format of "2020-07-08". When creating a new Date out of this value, my clientside Timezone was putting the end.date in at 5pm (17:00:00) on the previous day. This would mess up my results, because the current day's event would disappear at 5:00:01 pm.

For example, test this out around line 279, after "var isPast"

console.log(date); // -> 2020-07-08
var compareDate = new Date(date);
console.log(compareDate); // -> Tue Jul 07 2020 17:00:00 GMT-0700 (Mountain Standard Time)
date = date.split("-");
console.log(date); // -> date["2020", "07", "08"]
var compareDate = new Date(date);
console.log(compareDate); // -> Tue Jul 08 2020 00:00:00 GMT-0700 (Mountain Standard Time)

Therefore, around line 279, I added the following to fix my disappearing events.

var isPast = function isPast(date) {
        // START OF CODE ADDED
        console.log(date);
        // check date format before making comparison
        if (date.includes("-")) {
            //console.log("Date is wrong format to convert to new Date!");
            date = date.split("-");
        }
        // END OF CODE ADDED
        var compareDate = new Date(date);

Also, after line 239, I added a function to addTimeZone to the results that were printing to screen—since my printed elements were showing the wrong dates.

if (isAllDayEvent) {
            dateStart = addTimeZone(dateStart);
            dateEnd = addTimeZone(dateEnd);
            // report change to start and endtime
            //console.log(dateStart,dateEnd);
            // set the start and end time
            result.start.date = dateStart;
            result.end.date = dateEnd;
        }

This is what was added to function section. (This probably should be dynamically done, rather than hardcoded). My timezone is -7. = 7*60*60*100 = 25200000

 //Add timezone
    var addTimeZone = function addTimeZone(dateInfo) {
        return calculateDate(dateInfo, 25200000);
    };

Wakisashi avatar Jul 08 '20 06:07 Wakisashi