11 lines
407 B
Plaintext
11 lines
407 B
Plaintext
"use strict";
|
|
const daysInMonth = require("./daysInMonth.js");
|
|
function addMonths(date, months) {
|
|
const expectedMonth = date.getMonth() + months;
|
|
const tempMaxDay = daysInMonth(new Date(date.getFullYear(), expectedMonth, 1, 0, 0, 0, 0));
|
|
const currentDay = date.getDate();
|
|
date.setMonth(expectedMonth, currentDay > tempMaxDay ? tempMaxDay : currentDay);
|
|
return date;
|
|
}
|
|
module.exports = addMonths;
|