user-charge-rate
by Nic Fontaine
JavaScript
function monthlyCharge(month, subscription, users) {
var total = 0;
for (const u of users) {
const start = u.activatedOn;
const end = u.deactivatedOn || lastDayOfMonth(start);
//console.log(start.getMonth());
}
}
const users = [
{
id: 1,
name: 'Employee #1',
activatedOn: new Date('2019-01-01'),
deactivatedOn: null,
customerId: 1,
},
{
id: 2,
name: 'Employee #2',
activatedOn: new Date('2019-01-01'),
deactivatedOn: null,
customerId: 1,
},
];
const plan = {
id: 1,
customerId: 1,
monthlyPriceInCents: 5000,
};
console.log(monthlyCharge("2019-01", plan, users));
console.log(lastDayOfMonth(nextDay(new Date("2019-01"))).toString());
console.log(lastDayOfMonth(new Date("2019-01")).toString());
function firstDayOfMonth(date) {
return new Date(date.getFullYear(), date.getMonth(), 1)
}
function lastDayOfMonth(date) {
return new Date(date.getFullYear(), date.getMonth() + 1, 0)
}
function nextDay(date) {
return new Date(date.getFullYear(), date.getMonth(), date.getDate() + 1)
}