subtractMonths method

DateTime subtractMonths(
  1. int months
)

Implementation

DateTime subtractMonths(int months) {
  int newYear = year - (month - months - 1) ~/ 12;
  int newMonth = (month - months - 1) % 12 + 1;
  if (newMonth <= 0) {
    newYear -= 1;
    newMonth += 12;
  }
  int newDay = day;
  while (newDay > daysInMonth(newYear, newMonth)) {
    newDay--;
  }
  return DateTime(newYear, newMonth, newDay, hour, minute, second,
      millisecond, microsecond);
}