Working Days

use Derafu\Date\ValueObject\WorkCalendar;

A WorkCalendar knows which days are not working days: the days of the week that are weekend and the holidays. It does not change: the with*() methods give another calendar.

The holidays depend on the country and the year, so the package does not bring them: whoever uses the calendar gives them.

use Derafu\Date\Enum\Weekday;

$calendar = new WorkCalendar(
    holidays: ['2025-01-01', '2025-05-01'],
    weekend: [Weekday::SATURDAY, Weekday::SUNDAY],   // the default
);

The holidays are dates or texts written as Y-m-d (another text is an InvalidDateException). They are kept sorted and without repeating.

Ask

Method What it does
isHoliday($date) Whether the date is a holiday.
isWorkingDay($date) Whether it is not weekend and not a holiday.
addWorkingDays($date, $days) The date some working days later (earlier, if negative). The time is kept.
subtractWorkingDays($date, $days) The date some working days earlier.
getWorkingDayNumber($date) The number of a working day in its month (the first is 1), or null if the date is not a working day.
getNthWorkingDay($month, $number) The date of the working day of a month with a number, or null if the month does not have so many. A number less than 1 is an InvalidDateException.
isLastWorkingDay($date) Whether it is the last working day of its month.
countWorkingDays($from, $to) The working days of a range, both ends included.
getHolidays(), getWeekend() What the calendar was given.
$calendar->addWorkingDays('2025-01-03', 1);               // 2025-01-06 (Monday)
$calendar->getNthWorkingDay(Month::of(2025, 3), 1);       // 2025-03-03 (March 1 is a Saturday)
$calendar->getWorkingDayNumber('2025-03-03');             // 1

Other calendars

$calendar->withHolidays(['2026-01-01']);                      // other holidays, same weekend
$calendar->withWeekend([Weekday::FRIDAY, Weekday::SATURDAY]); // other weekend, same holidays
On this page

Last updated on 05/11/2026 by Anonymous