daysSpanned function

int daysSpanned(
  1. Date start,
  2. Date end, {
  3. bool inclusive = true,
})

The number of days spanned by the range defined by the two dates. Defaults to including the end date, so that daysSpanned(d, d) == 1.

Implementation

int daysSpanned(Date start, Date end, {bool inclusive = true}) =>
    // Use inHours / 24 instead of inDays to account for daylight savings
    (end.asUtcTime().difference(start.asUtcTime()).inHours / 24).round() +
    (inclusive ? 1 : 0);