FatulM / shamsi_date

A Flutter and Dart package for using Jalali (Shamsi, Solar, Persian, Jalaali, شمسی or خورشیدی) calendar. You can convert, format and manipulate Jalali and Gregorian (Miladi or میلادی) date and times.
https://pub.dev/packages/shamsi_date
BSD 3-Clause "New" or "Revised" License
78 stars 11 forks source link

Diff 2 dates #4

Closed mehrdad-shokri closed 4 years ago

mehrdad-shokri commented 4 years ago

Suppose I have 2 Jalali instances, how do I diff them in months? I suppose converting them back to DateTime and using difference method won't work, because there's no correlation between Jalali and Gregorian month diffs.

FatulM commented 4 years ago

Hi, You can use a simple method like this:

int diff(Jalali j1, Jalali j2) {
    return (j1.year - j2.year)*12 + (j1.month - j2.month);
}