addMonths method

DateTime addMonths(
  1. int months
)

Adds the specified number of months to the current DateTime.

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

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

Implementation

DateTime addMonths(int months) {
  if (months == 0) {
    // same
    return this;
  }

  // We used the Jiffy package to add years, months, etc
  // https://stackoverflow.com/questions/54792056/add-subtract-months-years-to-date-in-dart
  return Jiffy.parseFromDateTime(this).add(months: months).dateTime;
}