addMonths method

  1. @override
Jalali addMonths(
  1. int months
)
override

add months to this date this Method is safe for month and year bounds

throws DateException on month length or leap crash

throws on null argument

non-null

Implementation

@override
Jalali addMonths(int months) {
  ArgumentError.checkNotNull(months, 'months');

  if (months == 0) {
    return this;
  } else {
    // this is fast enough, no need for further optimization
    final int sum = month + months - 1;
    final int mod = sum % 12;
    // can not use "sum ~/ 12" directly
    final int deltaYear = (sum - mod) ~/ 12;

    return Jalali(year + deltaYear, mod + 1, day);
  }
}