monthsAgo method

DateTime monthsAgo (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 new DateTime(
      y, m, d, time.hour, time.minute, time.second, time.millisecond);
}