Last active
January 2, 2016 23:19
-
-
Save elight/8375352 to your computer and use it in GitHub Desktop.
Only getting dem Github notification emails on weekdays
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 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