Table of Contents

NotableDateTimeExtensions Class

Definition

Namespace
Bodu.Extensions
Assembly
Bodu.Globalization.Calendar.dll
Package
Bodu.Globalization.Calendar 1.0.1
Source
NotableDateTimeExtensions.AddWorkingDays.cs

Provides working-day, traversal, and notable-date query extension methods over DateTime, delegating to the DateOnly surface on the date component.

public static class NotableDateTimeExtensions
Inheritance
NotableDateTimeExtensions
Inherited Members

Examples

INotableDateService service = AmericasCalendarData.CreateService("US");
DateTime stamp = new(2026, 12, 25, 9, 30, 0, DateTimeKind.Local); // Christmas morning

bool working = stamp.IsWorkingDay(service, "US"); // false

// The next working day keeps the original 09:30 local time-of-day.
DateTime resume = stamp.NextWorkingDay(service, "US");

Remarks

Predicate and query methods evaluate the date component only. Traversal methods that return a moved DateTime preserve the original time-of-day and Kind.

Methods

AddWorkingDays(DateTime, int, INotableDateService, string, WeekPattern?)

Advances the date by a signed number of working days, preserving the time-of-day and kind.

public static DateTime AddWorkingDays(this DateTime date, int count, INotableDateService service, string territory, WeekPattern? workingWeek = null)

Parameters

date DateTime

The starting date.

count int

The number of working days to add; negative retreats, zero returns the date unchanged.

service INotableDateService

The service used to resolve notable dates.

territory string

The requested territory code.

workingWeek WeekPattern?

The working-week pattern, or null for Monday to Friday.

Returns

DateTime

The resulting date at the original time-of-day.

Exceptions

ArgumentNullException

service or territory is null.

EnumerateNonWorkingDays(DateTime, DateTime, INotableDateService, string, WeekPattern?)

Lazily enumerates the non-working days in the inclusive range, in ascending order, each at the start's time-of-day and kind.

public static IEnumerable<DateTime> EnumerateNonWorkingDays(this DateTime start, DateTime end, INotableDateService service, string territory, WeekPattern? workingWeek = null)

Parameters

start DateTime

The inclusive start date.

end DateTime

The inclusive end date.

service INotableDateService

The service used to resolve notable dates.

territory string

The requested territory code.

workingWeek WeekPattern?

The working-week pattern, or null for Monday to Friday.

Returns

IEnumerable<DateTime>

The non-working days in the range at the start's time-of-day.

Exceptions

ArgumentNullException

service or territory is null.

EnumerateNotableDates(DateTime, DateTime, INotableDateService, string, NotableDateFilter?)

Resolves the notable dates emitted within the inclusive range for the territory.

public static IReadOnlyList<NotableDate> EnumerateNotableDates(this DateTime start, DateTime end, INotableDateService service, string territory, NotableDateFilter? filter = null)

Parameters

start DateTime

The inclusive start date.

end DateTime

The inclusive end date.

service INotableDateService

The service used to resolve notable dates.

territory string

The requested territory code.

filter NotableDateFilter

An optional filter the occurrences must satisfy.

Returns

IReadOnlyList<NotableDate>

The emitted occurrences, ordered by date then identity.

Exceptions

ArgumentNullException

service or territory is null.

EnumerateWorkingDays(DateTime, DateTime, INotableDateService, string, WeekPattern?)

Lazily enumerates the working days in the inclusive range, in ascending order, each at the start's time-of-day and kind.

public static IEnumerable<DateTime> EnumerateWorkingDays(this DateTime start, DateTime end, INotableDateService service, string territory, WeekPattern? workingWeek = null)

Parameters

start DateTime

The inclusive start date.

end DateTime

The inclusive end date.

service INotableDateService

The service used to resolve notable dates.

territory string

The requested territory code.

workingWeek WeekPattern?

The working-week pattern, or null for Monday to Friday.

Returns

IEnumerable<DateTime>

The working days in the range at the start's time-of-day.

Exceptions

ArgumentNullException

service or territory is null.

GetNotableDates(DateTime, INotableDateService, string, NotableDateFilter?)

Gets the notable dates emitted on the date for the territory.

public static IReadOnlyList<NotableDate> GetNotableDates(this DateTime date, INotableDateService service, string territory, NotableDateFilter? filter = null)

Parameters

date DateTime

The date whose date component is resolved.

service INotableDateService

The service used to resolve notable dates.

territory string

The requested territory code.

filter NotableDateFilter

An optional filter the occurrences must satisfy.

Returns

IReadOnlyList<NotableDate>

The emitted occurrences; empty when there are none.

Exceptions

ArgumentNullException

service or territory is null.

IsNonWorkingDay(DateTime, INotableDateService, string, WeekPattern?)

Determines whether the date is a non-working day for the territory.

public static bool IsNonWorkingDay(this DateTime date, INotableDateService service, string territory, WeekPattern? workingWeek = null)

Parameters

date DateTime

The date whose date component is tested.

service INotableDateService

The service used to resolve notable dates.

territory string

The requested territory code.

workingWeek WeekPattern?

The working-week pattern, or null for Monday to Friday.

Returns

bool

true if the date is non-working; otherwise false.

Exceptions

ArgumentNullException

service or territory is null.

IsNotableDate(DateTime, INotableDateService, string, NotableDateFilter?)

Determines whether any notable date is emitted on the date for the territory.

public static bool IsNotableDate(this DateTime date, INotableDateService service, string territory, NotableDateFilter? filter = null)

Parameters

date DateTime

The date whose date component is tested.

service INotableDateService

The service used to resolve notable dates.

territory string

The requested territory code.

filter NotableDateFilter

An optional filter the occurrence must satisfy.

Returns

bool

true if at least one occurrence is emitted; otherwise false.

Exceptions

ArgumentNullException

service or territory is null.

IsWeekend(DateTime, WeekPattern?)

Determines whether the date falls outside the working week.

public static bool IsWeekend(this DateTime date, WeekPattern? workingWeek = null)

Parameters

date DateTime

The date whose date component is tested.

workingWeek WeekPattern?

The working-week pattern, or null for Monday to Friday.

Returns

bool

true if the date is not a working-week day; otherwise false.

IsWorkingDay(DateTime, INotableDateService, string, WeekPattern?)

Determines whether the date is a working day for the territory.

public static bool IsWorkingDay(this DateTime date, INotableDateService service, string territory, WeekPattern? workingWeek = null)

Parameters

date DateTime

The date whose date component is tested.

service INotableDateService

The service used to resolve notable dates.

territory string

The requested territory code.

workingWeek WeekPattern?

The working-week pattern, or null for Monday to Friday.

Returns

bool

true if the date is a working day; otherwise false.

Exceptions

ArgumentNullException

service or territory is null.

NextNonWorkingDay(DateTime, INotableDateService, string, WeekPattern?)

Returns the first non-working day strictly after the date, preserving the time-of-day and kind.

public static DateTime NextNonWorkingDay(this DateTime date, INotableDateService service, string territory, WeekPattern? workingWeek = null)

Parameters

date DateTime

The starting date.

service INotableDateService

The service used to resolve notable dates.

territory string

The requested territory code.

workingWeek WeekPattern?

The working-week pattern, or null for Monday to Friday.

Returns

DateTime

The next non-working day at the original time-of-day.

Exceptions

ArgumentNullException

service or territory is null.

InvalidOperationException

No non-working day is found within the traversal guard.

NextNotableDate(DateTime, INotableDateService, string, NotableDateFilter?)

Returns the earliest notable date emitted strictly after the date for the territory.

public static NotableDate? NextNotableDate(this DateTime date, INotableDateService service, string territory, NotableDateFilter? filter = null)

Parameters

date DateTime

The reference date whose date component is used.

service INotableDateService

The service used to resolve notable dates.

territory string

The requested territory code.

filter NotableDateFilter

An optional filter the occurrence must satisfy.

Returns

NotableDate

The next matching occurrence, or null when none exists up to the maximum year.

Exceptions

ArgumentNullException

service or territory is null.

NextWorkingDay(DateTime, INotableDateService, string, WeekPattern?)

Returns the first working day strictly after the date, preserving the time-of-day and kind.

public static DateTime NextWorkingDay(this DateTime date, INotableDateService service, string territory, WeekPattern? workingWeek = null)

Parameters

date DateTime

The starting date.

service INotableDateService

The service used to resolve notable dates.

territory string

The requested territory code.

workingWeek WeekPattern?

The working-week pattern, or null for Monday to Friday.

Returns

DateTime

The next working day at the original time-of-day.

Exceptions

ArgumentNullException

service or territory is null.

PreviousNonWorkingDay(DateTime, INotableDateService, string, WeekPattern?)

Returns the first non-working day strictly before the date, preserving the time-of-day and kind.

public static DateTime PreviousNonWorkingDay(this DateTime date, INotableDateService service, string territory, WeekPattern? workingWeek = null)

Parameters

date DateTime

The starting date.

service INotableDateService

The service used to resolve notable dates.

territory string

The requested territory code.

workingWeek WeekPattern?

The working-week pattern, or null for Monday to Friday.

Returns

DateTime

The previous non-working day at the original time-of-day.

Exceptions

ArgumentNullException

service or territory is null.

InvalidOperationException

No non-working day is found within the traversal guard.

PreviousNotableDate(DateTime, INotableDateService, string, NotableDateFilter?)

Returns the most recent notable date emitted strictly before the date for the territory.

public static NotableDate? PreviousNotableDate(this DateTime date, INotableDateService service, string territory, NotableDateFilter? filter = null)

Parameters

date DateTime

The reference date whose date component is used.

service INotableDateService

The service used to resolve notable dates.

territory string

The requested territory code.

filter NotableDateFilter

An optional filter the occurrence must satisfy.

Returns

NotableDate

The previous matching occurrence, or null when none exists down to the minimum year.

Exceptions

ArgumentNullException

service or territory is null.

PreviousWorkingDay(DateTime, INotableDateService, string, WeekPattern?)

Returns the first working day strictly before the date, preserving the time-of-day and kind.

public static DateTime PreviousWorkingDay(this DateTime date, INotableDateService service, string territory, WeekPattern? workingWeek = null)

Parameters

date DateTime

The starting date.

service INotableDateService

The service used to resolve notable dates.

territory string

The requested territory code.

workingWeek WeekPattern?

The working-week pattern, or null for Monday to Friday.

Returns

DateTime

The previous working day at the original time-of-day.

Exceptions

ArgumentNullException

service or territory is null.

SnapToNearestWorkingDay(DateTime, INotableDateService, string, WeekPattern?)

Returns the date if it is a working day; otherwise the nearest working day, preserving the time-of-day and kind.

public static DateTime SnapToNearestWorkingDay(this DateTime date, INotableDateService service, string territory, WeekPattern? workingWeek = null)

Parameters

date DateTime

The date to snap.

service INotableDateService

The service used to resolve notable dates.

territory string

The requested territory code.

workingWeek WeekPattern?

The working-week pattern, or null for Monday to Friday.

Returns

DateTime

The nearest working day at the original time-of-day.

Exceptions

ArgumentNullException

service or territory is null.

SnapToWorkingDay(DateTime, INotableDateService, string, WeekPattern?)

Returns the date if it is a working day; otherwise the next working day, preserving the time-of-day and kind.

public static DateTime SnapToWorkingDay(this DateTime date, INotableDateService service, string territory, WeekPattern? workingWeek = null)

Parameters

date DateTime

The date to snap.

service INotableDateService

The service used to resolve notable dates.

territory string

The requested territory code.

workingWeek WeekPattern?

The working-week pattern, or null for Monday to Friday.

Returns

DateTime

The date or the next working day, at the original time-of-day.

Exceptions

ArgumentNullException

service or territory is null.

SnapToWorkingDayBackward(DateTime, INotableDateService, string, WeekPattern?)

Returns the date if it is a working day; otherwise the previous working day, preserving the time-of-day and kind.

public static DateTime SnapToWorkingDayBackward(this DateTime date, INotableDateService service, string territory, WeekPattern? workingWeek = null)

Parameters

date DateTime

The date to snap.

service INotableDateService

The service used to resolve notable dates.

territory string

The requested territory code.

workingWeek WeekPattern?

The working-week pattern, or null for Monday to Friday.

Returns

DateTime

The date or the previous working day, at the original time-of-day.

Exceptions

ArgumentNullException

service or territory is null.

WorkingDaysBetween(DateTime, DateTime, INotableDateService, string, WeekPattern?)

Counts the working days in the inclusive range bounded by the two dates, regardless of their order.

public static int WorkingDaysBetween(this DateTime start, DateTime end, INotableDateService service, string territory, WeekPattern? workingWeek = null)

Parameters

start DateTime

One end of the range.

end DateTime

The other end of the range.

service INotableDateService

The service used to resolve notable dates.

territory string

The requested territory code.

workingWeek WeekPattern?

The working-week pattern, or null for Monday to Friday.

Returns

int

The number of working days in the inclusive range.

Exceptions

ArgumentNullException

service or territory is null.

Applies to

ProductVersions
.NET8, 10

See Also