how to get the duration of a CalendarEvent objet ? (there is no method for that !)

703 views
Skip to first unread message

emt ispa

unread,
Jul 16, 2019, 5:38:35 AM7/16/19
to Google Apps Script Community

hi,

i try to calculate the durations of several events in my google calendar and report them into a google spread sheet with apps script.

i don't find any method to get the length, the duration, of an event ( CalendarEvent objet ) , is it normal or the name (of duration) is not meaning ?

As time calculation/computing is a basic feature of calendar/sheet/time data, i am very surprise of this missing feature !

so, how can i get the duration ?
do i need to perform it myself with end-begin data valeue and manager the result, the format, the limits, the bound... ?
Something like MyDuration= getEndTime()-getStartTime() ..... ?


Maybe the function is in another google object, shall you help me or advice me ?

Thank you for your help.

Pierre

Clark Lind

unread,
Jul 16, 2019, 7:54:13 AM7/16/19
to google-apps-sc...@googlegroups.com
Pierre, I believe you have the only answer. I don't see a built-in function. I would also throw in a check to see if it is an all-day event. Something like:

if (event.isAllDayEvent() == False) {
  MyDuration = getEndTime() - getStartTime();
}

or something like that. Or just write a function and call it as needed..

function getDuration(end, start) {
  var duration =    etc etc
  return duration;
}

myDuration = getDuration(event.getEndTime() - event.getStartTime());
Reply all
Reply to author
Forward
0 new messages