monthsFromNow method

DateTime monthsFromNow(
  1. int months
)

Return the point in time months from now on the same date.

If the current day of the month isn't valid in the new month, the nearest valid day in the new month will be used.

Implementation

DateTime monthsFromNow(int months) {
  var time = now();
  var month = (time.month + months - 1) % 12 + 1;
  var year = time.year + (months + time.month - 1) ~/ 12;
  var day = clampDayOfMonth(year: year, month: month, day: time.day);
  return DateTime(year, month, day, time.hour, time.minute, time.second,
      time.millisecond);
}