startOfBusinessWeek method

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

Returns the start of the business week.

By default, returns Monday. For Middle Eastern config, returns Sunday.

Implementation

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

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

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

  return current;
}