totalDayInRangeYear static method

int totalDayInRangeYear({
  1. required int fromYear,
  2. int? toYear,
})

Get total day depend of from & to year defined

final total = GlobalFunction.totalDayInRangeYear(from: 2020, to:2021)

print(total) // 731

Implementation

static int totalDayInRangeYear({
  required int fromYear,
  int? toYear,
}) {
  /// If not defined [toYear], give default value from [fromYear]
  toYear ??= fromYear;

  if (fromYear > toYear) {
    throw Exception("[Year From] can't be greather than [Year To]");
  }

  if (fromYear == toYear) {
    return totalDayInYear(fromYear);
  }

  int totalDay = 0;
  for (int i = fromYear; i <= toYear; i++) {
    totalDay += totalDayInYear(i);
  }

  return totalDay;
}