yearsAgo method

DateTime yearsAgo(
  1. int years
)

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

If the current day of the month isn't valid in the new year, the nearest valid day in the original month will be used.

Implementation

DateTime yearsAgo(int years) {
  var time = now();
  var year = time.year - years;
  var day = clampDayOfMonth(year: year, month: time.month, day: time.day);
  return DateTime(year, time.month, day, time.hour, time.minute, time.second,
      time.millisecond);
}