Created
September 11, 2014 15:24
-
-
Save gcchaan/560a501b9f0eedc39f0f to your computer and use it in GitHub Desktop.
自分のカレンダーの業務時間あたりに翌々月の祝日を自動でセットする。月1でトリガー。moment.jsが必要
This file contains 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 setHoliday() { | |
var startTime = momentjs.moment().add('months', 2).date(1); | |
var endTime; | |
var end = momentjs.moment(); | |
var daysInMonth = end.daysInMonth(); | |
endTime = end.add('months', 2).date(daysInMonth); | |
var holidayCalendar = CalendarApp.getCalendarById( | |
'ja.japanese#[email protected]'); | |
var mstHoliday = holidayCalendar.getEvents(new Date(startTime), new Date(endTime)); | |
for (var i = 0;i < mstHoliday.length;i++) { | |
var holidayDate = mstHoliday[i].getAllDayStartDate(); | |
var holidayStart = momentjs.moment(holidayDate).hour(09); | |
var holidayEnd = momentjs.moment(holidayDate).hour(18); | |
CalendarApp.getDefaultCalendar().createEvent( | |
'祝日('+ mstHoliday[i].getTitle() +')', | |
new Date(holidayStart), | |
new Date(holidayEnd) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment