add method

  1. @override
Jalali add({
  1. int years = 0,
  2. int months = 0,
  3. int days = 0,
  4. int hours = 0,
  5. int minutes = 0,
  6. int seconds = 0,
})
override

add days, months and years separately note: it does not make any conversion, it simply adds to each field value for subtracting simple add negative value

UNSAFE

throws on null arguments

non-null

Implementation

@override
Jalali add(
    {int years = 0,
    int months = 0,
    int days = 0,
    int hours = 0,
    int minutes = 0,
    int seconds = 0}) {
  ArgumentError.checkNotNull(years, 'years');
  ArgumentError.checkNotNull(months, 'months');
  ArgumentError.checkNotNull(hours, 'hours');
  ArgumentError.checkNotNull(minutes, 'minutes');
  ArgumentError.checkNotNull(seconds, 'seconds');

  if (years == 0 &&
      months == 0 &&
      days == 0 &&
      hours == 0 &&
      minutes == 0 &&
      seconds == 0) {
    return this;
  } else {
    years += year;
    months += month;
    days += day;
    hours += hour;
    minutes += minute;
    seconds += second;

    minutes += seconds ~/ 60;
    seconds = seconds % 60;

    hours += minutes ~/ 60;
    minutes = minutes % 60;

    days += hours ~/ 24;
    hours = hours % 24;

    months += days ~/ monthLength;
    days = days % monthLength;

    years += months ~/ 12;
    months = months % 12;

    return Jalali(years, months, days, hours, minutes, seconds);
  }
}