previousMonth method

DateTime previousMonth (DateTime m)

Retuns a new DateTime in the previous calendar month.

If the month is January (01), the retuned 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 new DateTime(year, month);
}