Created
April 17, 2022 07:06
-
-
Save mikkipastel/e55d107853df59ac80a94dd401f66900 to your computer and use it in GitHub Desktop.
create function for get today is holiday event
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 checkTodayIsHoliday(webhook) { | |
let minNow = new Date(); | |
minNow.setHours(7, 0, 0, 0); | |
const timeMin = minNow.toISOString(); | |
let maxNow = new Date(); | |
maxNow.setDate(maxNow.getDate() + 1); | |
maxNow.setHours(7, 0, -1, 0); | |
const timeMax = (new Date(maxNow)).toISOString(); | |
axios.get( | |
getGoogleCalendarApiPath(process.env.CALENDAR_HOLIDAY_IN_BNAGKOK_ID), | |
{ | |
params: { | |
orderBy: 'startTime', | |
singleEvents: true, | |
key: process.env.GOOGLE_API_KEY, | |
timeMin: timeMin, | |
timeMax: timeMax, | |
maxResults: 1 | |
} | |
} | |
).then(function (response) { | |
const nowDate = timeMin.split('T')[0]; | |
if (response.data.items.length > 0 && nowDate == response.data.items[0].start.date) { | |
const printText = 'วันนี้เป็น' + response.data.items[0].summary | |
console.log(printText); | |
webhook.send(printText, {}); | |
true; | |
} else { | |
console.log('Today is not Holiday'); | |
webhook.send('@everyone, standup meeting', {}); | |
false; | |
} | |
}).catch(function (error) { | |
console.log(error); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment