Skip to content

Instantly share code, notes, and snippets.

@tanjo
Last active August 29, 2015 14:04
Show Gist options
  • Save tanjo/05b02d4db4074e21d7ef to your computer and use it in GitHub Desktop.
Save tanjo/05b02d4db4074e21d7ef to your computer and use it in GitHub Desktop.
SpreadsheetFromGoogleHolidays

SpreadsheetFromGoogleHolidays

Google カレンダーから休日を取得して、 Google Spreadsheet にて利用する

holiday.DAY_SUNDAY = 0;
holiday.DAY_SATURDAY = 6;
var now = new Date();
var nowString = now.getFullYear() + '-' + ('0' + (now.getMonth() + 1)).slice(-2) + '-' + ('0' + now.getDate()).slice(-2);
var holidays = getHolidays();
if (holiday.DAY_SUNDAY >= now.getDay() || now.getDay() >= holiday.DAY_SATURDAY) {
return;
}
for (var i = 0; i < holidays.length; i++) {
if (holidays[i].date == nowString) {
return;
}
}
// 平日の処理
function getHolidays() {
var now = new Date();
var start = now.getFullYear() + '-' + ('0' + (now.getMonth() + 1)).slice(-2) + '-' + ('0' + now.getDate()).slice(-2);
// 一年後のまでの休日
var end = (now.getFullYear() + 1) + '-' + ('0' + (now.getMonth() + 1)).slice(-2) + '-' + ('0' + now.getDate()).slice(-2);
// 最大休日取得数
var max = 50;
var url = 'http://74.125.235.142/calendar/feeds/'
+ 'outid3el0qkcrsuf89fltf7a4qbacgt9@import.calendar.google.com'
+ '/public/full-noattendees?start-min='
+ start
+ '&start-max='
+ end
+ '&max-results='
+ max
+ '&alt=json';
var response = UrlFetchApp.fetch(url);
var jsonObject = JSON.parse(response);
var holidays = [];
for (var i = 0; i < jsonObject['feed']["entry"].length; i++) {
var info = jsonObject['feed']['entry'][i];
var date = info['gd$when'][0]['startTime'];
var title = info['title']['$t']
holidays[i] = { 'title':title, 'date':date };
}
return holidays
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment