event.start.dateTime is equal to a certain time

52 views
Skip to first unread message

Diego Delfino

unread,
Nov 22, 2022, 8:07:59 AM11/22/22
to Google Apps Script Community
Hi, 
i'm trying to do something pretty basic but i'm stuck.
i would like the script to return me a simple YES/NO based on if an event start time is midnight or not.
This is due to the fact that all-day events that include resources (i.e. meeting room booking) they always get the 0:00 time added....

Here's the part of the script:

      if (event.start.dateTime) {
        var start = Utilities.formatDate(new Date(event.start.dateTime),Session.getScriptTimeZone(),'dd.MM.yyyy HH:mm') ;
      } else {
        var start = event.start.date;
      }
      var timeZone = Session.getScriptTimeZone();
      var allDay = event.start.dateTime = "00:00" ? 'NO' : 'YES'


Thanks in advance
Diego

cwl...@gmail.com

unread,
Nov 22, 2022, 8:13:56 AM11/22/22
to Google Apps Script Community
You can probably simplify and just grab the desired number of events (say, a week's worth), the iterate over each event and call isAllDayEvent().
It is a Boolean, so will return true or false.   Good luck!

Diego Delfino

unread,
Nov 22, 2022, 8:24:36 AM11/22/22
to Google Apps Script Community
thanks for the reply. 

my problem is that AllDayEvent doesn't work in my case. 
The all day events are automatically converted by google calendar, because of resources inside the event itself:


So the only way to recognize if an event is an allDay or not is whether the starting time is midnight...

cwl...@gmail.com

unread,
Nov 22, 2022, 10:35:30 PM11/22/22
to Google Apps Script Community
I just noticed something... it could just be a simple typo. 
var allDay = event.start.dateTime = "00:00" ? 'NO' : 'YES'   change this to:

var allDay = event.start.dateTime == "00:00" ? 'NO' : 'YES'  //it doesn't look like you were checking for equality
Reply all
Reply to author
Forward
0 new messages