monthsAgo method

DateTime monthsAgo(
  1. int months
)

Return the point in time months ago on the same date.

Implementation

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