addMonthsToMonthDate function

NepaliDateTime addMonthsToMonthDate(
  1. NepaliDateTime monthDate,
  2. int monthsToAdd
)

Add a given number of months to a NepaliDateTime object. monthDate is the NepaliDateTime object to which the months are to be added. monthsToAdd is the number of months to add. Returns a new NepaliDateTime object with the given number of months added to the input.

Implementation

NepaliDateTime addMonthsToMonthDate(NepaliDateTime monthDate, int monthsToAdd) {
  var year = monthDate.year;
  var month = monthDate.month + monthsToAdd;

  year += (month - 1) ~/ 12;
  month = month % 12;
  if (month == 0) month = 12;
  return NepaliDateTime(year, month);
}