businessDaysBetween method

int businessDaysBetween(
  1. Hora other, [
  2. BusinessDayConfig config = BusinessDayConfig.standard
])

Returns the number of business days between this and other.

The result is positive if other is after this, negative otherwise.

Implementation

int businessDaysBetween(
  Hora other, [
  BusinessDayConfig config = BusinessDayConfig.standard,
]) {
  if (!isValid || !other.isValid) return 0;

  final start = isBefore(other) ? this : other;
  final end = isBefore(other) ? other : this;
  final sign = isBefore(other) ? 1 : -1;

  var count = 0;
  var current = start;

  while (current.isBefore(end)) {
    if (current.isBusinessDay(config)) {
      count++;
    }
    current = current.add(1, TemporalUnit.day);
  }

  return count * sign;
}