Skip to content

Instantly share code, notes, and snippets.

@elight
Last active January 2, 2016 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elight/8375352 to your computer and use it in GitHub Desktop.
Save elight/8375352 to your computer and use it in GitHub Desktop.
Only getting dem Github notification emails on weekdays
function whitelistGithub() {
if (isWeekend() || isEvening()) { return; }
var label = GmailApp.getUserLabelByName("github");
var threads = label.getThreads();
for (var i = 0; i < threads.length; i++) {
if (threads[i].isUnread()) {
threads[i].moveToInbox();
}
}
}
function isWeekend() {
return (
isSaturdayOrSunday() ||
isFridayEvening() ||
isMondayMorning()
);
}
function isEvening() {
var hour = (new Date()).getHours();
return (hour < 7 || hour > 18);
}
function isSaturdayOrSunday() {
var day = (new Date()).getDay();
return (day === 0 || day === 6);
}
function isFridayEvening() {
var d = new Date();
var day = d.getDay();
var hour = d.getHours();
return (day == 5 && hour > 18);
}
function isMondayMorning() {
var d = new Date();
var day = d.getDay();
var hour = d.getHours();
return (day == 1 && hour < 8);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment