FormatGoogleCalendar
FormatGoogleCalendar copied to clipboard
All day event
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.
I'm seeing the same thing.
Actually I've made some changes to the plugin and translate to spanish, and I can fix that
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.
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;
}
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 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.
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, your fix works wonderfully! Please submit a pull request!
@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); }
My fix still works: https://millhousenchurch.com/js/format-google-calendar.js
Sorry for the delay! This fix still works for me.
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.
Has anyone found an adequate fix for this?
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);
};