previousMonth method

DateTime previousMonth (DateTime m)

Returns a new DateTime in the previous calendar month.

If the month is January (01), the returned DateTime is in the previous year

Implementation

static DateTime previousMonth(DateTime m) {
  var year = m.year;
  var month = m.month;
  if (month == 1) {
    year--;
    month = 12;
  } else {
    month--;
  }
  return normalizeDate(DateTime(year, month));
}