WorkCalendar
When work happens: the days of the week that are worked and the dates that are not.
public sealed class WorkCalendar
Remarks
Maps between calendar dates and the working-day axis the scheduler counts on. Index 0 is Origin, the project's first working day. IndexOf(DateTime) and DateAt are exact inverses on working days; IndexOf(DateTime) on a weekend or holiday answers the next working day's index, which is what both a planned start and a drop on the timeline mean by a date that cannot be worked. The axis is built lazily in both directions and cached, so the first question about a date ten years out costs one walk and every later one a binary search.
Members at a glance
WorkCalendar | Creates a calendar whose first working day is origin or the next one after it. |
DateAt | The date of a working-day index. |
IndexOf | The working-day index of a date, rounding a weekend or holiday forward to the next working day. |
IsWorkingDay | Whether a date is worked. |
ToDate | The project's first working day: working-day index 0. |
WorkingDaysBetween | Working days from one date to another, both inclusive; zero when the second is earlier. |
DefaultWorkingDays | Monday to Friday. |
Constructors
WorkCalendar
Creates a calendar whose first working day is origin or the next one after it.
- origin
- The first day work could happen.
- workingDays
- The days of the week that are worked; null or empty for Monday to Friday.
- holidays
- Dates that are not worked; null for none.
Methods
DateAt
The date of a working-day index.
- index
- The index; negative counts back from
Origin.
Returns. The working day at that index.
IndexOf
The working-day index of a date, rounding a weekend or holiday forward to the next working day.
- date
- The date.
Returns. Its index on the working-day axis; negative before Origin.
IsWorkingDay
Whether a date is worked.
- date
- The date; its time of day is ignored.
Returns. True for a working day.
ToDate
The project's first working day: working-day index 0.
WorkingDaysBetween
Working days from one date to another, both inclusive; zero when the second is earlier.
- from
- The first day.
- to
- The last day.
Returns. The number of working days in the range.
Fields
DefaultWorkingDays
Monday to Friday.