calendarAddYears function

DateTime calendarAddYears(
  1. DateTime dt,
  2. int years
)

Implementation

DateTime calendarAddYears(DateTime dt, int years) {
  final y = dt.year + years;
  final m = dt.month;
  final d = dt.day;
  final maxDay = _daysInMonth(y, m);
  final day = d > maxDay ? maxDay : d;
  return dt.isUtc
      ? DateTime.utc(y, m, day, dt.hour, dt.minute, dt.second, dt.millisecond, dt.microsecond)
      : DateTime(y, m, day, dt.hour, dt.minute, dt.second, dt.millisecond, dt.microsecond);
}