addYears method

  1. @useResult
DateTime addYears(
  1. int years
)

Adds the specified number of years to the current DateTime.

Note: When adding a year to February 29th, it returns February 28th (not March 1st)

Args: years (int): The number of years to add.

Returns: DateTime: A new DateTime object with the added years.

Implementation

@useResult
DateTime addYears(int years) {
  if (years == 0) {
    return this;
  }

  return Jiffy.parseFromDateTime(this).add(years: years).dateTime;
}