-
-
Save martynchamberlin/10d5d55ad2f9e2a4f4afebd9a1d4d857 to your computer and use it in GitHub Desktop.
Calculate how many more builds you can create today on a free Codeship account in order to not be overstepping your average daily allotment
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
/** | |
* This function gratefully taken from | |
* http://stackoverflow.com/a/1185804/1591507 | |
*/ | |
Date.prototype.monthDays = () => { | |
const date = new Date(); | |
const d = new Date(date.getFullYear(), date.getMonth() + 1, 0); | |
return d.getDate(); | |
} | |
/** | |
* @param {string} numberofBuildsDone - the number of builds | |
* that you’ve already used for the current month | |
*/ | |
const calc = (numberofBuildsDone) => { | |
const numberFreeBuildsPerMonth = 100; | |
const daysInMonth = new Date().monthDays(); | |
const currentDayInMonth = new Date().getDate(); | |
const availableBuildsPerDay = numberFreeBuildsPerMonth / daysInMonth; | |
const numBuildsLeftForToday = Math.round((availableBuildsPerDay * currentDayInMonth) - numberofBuildsDone); | |
return `You can make ${numBuildsLeftForToday} more builds today.`; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment