Skip to content

Instantly share code, notes, and snippets.

@martynchamberlin
Last active February 14, 2017 15:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martynchamberlin/10d5d55ad2f9e2a4f4afebd9a1d4d857 to your computer and use it in GitHub Desktop.
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 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