+ if (!apiKey) {
+ reportError("Specify a googleCalendarApiKey. See http://fullcalendar.io/docs/google_calendar/");
+ return {}; // an empty source to use instead. won't fetch anything.
+ }
+
+ // The API expects an ISO8601 datetime with a time and timezone part.
+ // Since the calendar's timezone offset isn't always known, request the date in UTC and pad it by a day on each
+ // side, guaranteeing we will receive all events in the desired range, albeit a superset.
+ // .utc() will set a zone and give it a 00:00:00 time.
+ if (!start.hasZone()) {
+ start = start.clone().utc().add(-1, 'day');
+ }
+ if (!end.hasZone()) {
+ end = end.clone().utc().add(1, 'day');
+ }
+
+ // when sending timezone names to Google, only accepts underscores, not spaces
+ if (timezone && timezone != 'local') {
+ timezoneArg = timezone.replace(' ', '_');
+ }
+
+ data = $.extend({}, sourceOptions.data || {}, {
+ key: apiKey,
+ timeMin: start.format(),
+ timeMax: end.format(),
+ timeZone: timezoneArg,
+ singleEvents: true,
+ maxResults: 9999
+ });
+