endOfBusinessWeek method

Hora endOfBusinessWeek([
  1. BusinessDayConfig config = BusinessDayConfig.standard
])

Returns the end of the business week.

Implementation

Hora endOfBusinessWeek([
  BusinessDayConfig config = BusinessDayConfig.standard,
]) {
  var current = startOf(TemporalUnit.day);

  // Find the last non-weekend day of the week
  while (config.weekendDays.contains(current.weekday)) {
    current = current.add(1, TemporalUnit.day);
  }

  // Go forward to the end of the business week
  while (!config.weekendDays.contains(
    current.add(1, TemporalUnit.day).weekday,
  )) {
    current = current.add(1, TemporalUnit.day);
  }

  return current.endOf(TemporalUnit.day);
}