开发者

Google App Script Calendar API - createAllDayEvent() method not working as expected

开发者 https://www.devze.com 2023-03-18 03:19 出处:网络
I\'ve opened an issue about (what I assume) is a bug in Google App Scripts but it doesn\'t look like its being monitored so I wondering if anyone has a work around for my problem.

I've opened an issue about (what I assume) is a bug in Google App Scripts but it doesn't look like its being monitored so I wondering if anyone has a work around for my problem.

In summary I am running a script (via a google spreadsheet) which attempts to put an entry in a Google Calendar I created.

function testCalendarAllDayEvent(){
  var calendar = CalendarApp.getCalendarById("od4434jhedv936p65gcbl3bjg@group.calendar.google.com");
  var calTimezone = calendar.getTimeZone();
  var scriptTimezone = Session.getTimeZone();
  var calendarevent = calendar.createAllDayEvent("Test Event", new Date(2011,7,1));
  var summary = calendarevent.getStartTime();
}

So the above code adds the "Test Event" on the 31st July 2011 instead of the 1st July. If I change it to new Date (201开发者_开发百科1,7,2)it puts it in on the 1st August 2011. So it seems to be 30 days out. The reason I look at the time zones it to ensure they are the same. When I look at the summary variable value it is Mon Aug 01 2011 01:00:00 GMT+0100 (IST)

I don't want to blindly add 30 days to all dates as it will just end in tears. Does anyone know if what I am doing is incorrect? I've used Google examples as templates.


The issue here is that the Date constructor takes a zero-based month index. So

new Date(2011,7,1) creates a Date of Aug 1 2011.

whereas

new Date(2011,6,1) creates a Date of July 1 2011.

0

精彩评论

暂无评论...
验证码 换一张
取 消