HypernovaDesktop Components · docs
Binarymission
WinForms › Project Management › WorkCalendar

WorkCalendar

class.NET 6 / 8 / 10.NET Framework 4.8Binarymission.WinForms.Controls.ProjectManagement

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

WorkCalendarCreates a calendar whose first working day is origin or the next one after it.
DateAtThe date of a working-day index.
IndexOfThe working-day index of a date, rounding a weekend or holiday forward to the next working day.
IsWorkingDayWhether a date is worked.
ToDateThe project's first working day: working-day index 0.
WorkingDaysBetweenWorking days from one date to another, both inclusive; zero when the second is earlier.
DefaultWorkingDaysMonday to Friday.

Constructors

WorkCalendar

public WorkCalendar(DateTime origin, IEnumerable<DayOfWeek> workingDays

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

public DateTime DateAt(int index)

The date of a working-day index.

index
The index; negative counts back from Origin.

Returns. The working day at that index.

IndexOf

public int IndexOf(DateTime date)

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

public bool IsWorkingDay(DateTime date)

Whether a date is worked.

date
The date; its time of day is ignored.

Returns. True for a working day.

ToDate

public DateTime Origin

The project's first working day: working-day index 0.

WorkingDaysBetween

public int WorkingDaysBetween(DateTime from, DateTime to)

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

public static readonly IReadOnlyList<DayOfWeek> DefaultWorkingDays

Monday to Friday.