Create a gist now

Instantly share code, notes, and snippets.

@martynchamberlin /index.js Secret
Last active Feb 14, 2017

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