MMRIZE / MMM-CalendarExt3

MagicMirror calendar view module
MIT License
58 stars 22 forks source link

MMM-GoogleCalendar Integration Shows All Day Event Times Incorrectly #36

Closed nickloudermilk closed 1 year ago

nickloudermilk commented 2 years ago

When all day events are pulled from MMM-GoogleCalendar broadcast, they appear to start the prior day at 7 PM (5 hours before their actual starting time of midnight). I am in a time zone that is exactly UTC-5.

MMM-GoogleCalendar Config:

{
            module: 'MMM-GoogleCalendar',
            hiddenOnStartup: true,
            config: {
                broadcastPastEvents: true,
                broadcastEvents: true,
                calendars: [

MMM-CalendarExt3 Config:

{
            module: "MMM-CalendarExt3",
            position: "bottom_bar",
            config: {
                weeksInView: 3,
                weekIndex: 0,
                firstDayOfWeek: 0,
                locale: 'en-US',
                useSymbol: false,
                fontSize: "20px",
eventTransformer: (e) => {
  e.startDate = new Date(e.start?.date || e.start?.dateTime).valueOf()
  e.endDate = new Date(e.end?.date || e.end?.dateTime).valueOf()
  e.title = e.summary
  e.fulldayEvent = (e.start?.date) ? true : false
  return e
}
            }
          }, 

Screenshot

eouia commented 2 years ago

How about it displayed on the original MMM-GoogleCalendar module? Frankly, this module doesn't parse the time of event. MMM-GoogleCalendar parses the event time, then this module use the parsed result. So, if the time is not parsed properly, maybe it might be the business of MMM-GoogleCalendar.

nickloudermilk commented 2 years ago

All day events appear correctly in the original MMM-GoogleCalendar module. Times for events that are not all day appear correctly. I.e. in the example above, "Matt out" does start at 8:00 AM local time on Tuesday.

Bovive commented 1 year ago

I was able to modify the transformer added to the config so that it adjusted all day events to match my time zone. Here is an example:

eventTransformer: (e) => { e.startDate = new Date(e.start?.date || e.start?.dateTime).valueOf() e.endDate = new Date(e.end?.date || e.end?.dateTime).valueOf() e.title = e.summary e.fulldayEvent = (e.start?.date) ? true : false const oneSecond = 1000; // 1,000 milliseconds const oneMinute = oneSecond 60; const oneHour = oneMinute 60; const oneDay = oneHour 24; const timeCorrect = oneHour 6; if (e.fulldayEvent) e.startDate += timeCorrect; return e }

In my case my timeCorrect = oneHour * 6 because I am UTC -6.

ccortellinijc commented 1 year ago

The eventTransformer arrow function has a bug in it. When you create a date without a time, you will get potentially different results for the default time. For example new Date('01/01/2023') sets the timezone to my local, but the Google date format new Date('2023-01-01') sets it to UTC. So, I corrected this as follows:

eventTransformer: (e) => {
  e.startDate = new Date(e.start?.date ? e.start.date + ' 00:00' : null || e.start?.dateTime).valueOf()
  e.endDate = new Date(e.end?.date ? e.end.date + ' 00:00' : null || e.end?.dateTime).valueOf()
  e.title = e.summary
  e.fulldayEvent = (e.start?.date) ? true : false
  return e
}
eouia commented 1 year ago

@ccortellinijc That is a great point! I never have realized new Date('2023-01-01') and new Date('01/01/2023') have different result! Anyway I'm waiting Temporal API is introduced in real JS world. JS default Date object is not perfect to handle calendar things. After Temporal API, I'll rewrite the whole module with it.

I'll change the tip with yours in README.md in the next update. Thanks.

ruralguru commented 1 year ago

used @ccortellinijc tip:

This fixed multi-day events. Single day events now display as regular events starting at 12:00 AM. @ccortellinijc was that the effect you had as well or am I missing content?

eouia commented 1 year ago

@ruralguru The root of this issue would be caused by this - MMM-GoogleCalendar doesn't respect the default calendar module's broadcasting event notification format.

The easy and conventional way to solve this issue might be; Ask the developer of MMM-GoogleCalendar to edit that format to be compatible with de-facto default event format.

ruralguru commented 1 year ago

I was struggling to see the event structure. Thank you for noting the deviations. I suspected the ? Was an inquiry, just couldn't find the start.date reference rather than startDate. I was thinking of requesting or forking the google calendar, but my time is limited such that I can't support my request. I try to ask questions that lead to me at least supporting the answer.

eouia commented 1 year ago

Check #31