Google カレンダーから休日を取得して、 Google Spreadsheet にて利用する
Last active
August 29, 2015 14:04
-
-
Save tanjo/05b02d4db4074e21d7ef to your computer and use it in GitHub Desktop.
SpreadsheetFromGoogleHolidays
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
// 平日の処理 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/' | |
+ '[email protected]' | |
+ '/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