differenceInMonths method

int differenceInMonths(
  1. PersianDate other
)

Number of whole Jalali months from other to this date, ignoring the time of day.

Positive when this date is later. A month is complete when other.addMonths(n) is not past this date, and addMonths clamps the day, so date.addMonths(n).differenceInMonths(date) == n: 1403/06/31 to 1403/07/30 is one month.

Implementation

int differenceInMonths(PersianDate other) {
  if (this < other) return -other.differenceInMonths(this);
  final months = (year - other.year) * 12 + month - other.month;
  final day = other.day < monthLength ? other.day : monthLength;
  return day > this.day ? months - 1 : months;
}