NotableDateTimeExtensions Class
Definition
- Namespace
- Bodu.Extensions
- Assembly
- Bodu.Globalization.Calendar.dll
- Package
- Bodu.Globalization.Calendar 1.0.1
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
dateDateTimeThe starting date.
countintThe number of working days to add; negative retreats, zero returns the date unchanged.
serviceINotableDateServiceThe service used to resolve notable dates.
territorystringThe requested territory code.
workingWeekWeekPattern?The working-week pattern, or null for Monday to Friday.
Returns
- DateTime
The resulting date at the original time-of-day.
Exceptions
- ArgumentNullException
serviceorterritoryis 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
startDateTimeThe inclusive start date.
endDateTimeThe inclusive end date.
serviceINotableDateServiceThe service used to resolve notable dates.
territorystringThe requested territory code.
workingWeekWeekPattern?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
serviceorterritoryis 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
startDateTimeThe inclusive start date.
endDateTimeThe inclusive end date.
serviceINotableDateServiceThe service used to resolve notable dates.
territorystringThe requested territory code.
filterNotableDateFilterAn optional filter the occurrences must satisfy.
Returns
- IReadOnlyList<NotableDate>
The emitted occurrences, ordered by date then identity.
Exceptions
- ArgumentNullException
serviceorterritoryis 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
startDateTimeThe inclusive start date.
endDateTimeThe inclusive end date.
serviceINotableDateServiceThe service used to resolve notable dates.
territorystringThe requested territory code.
workingWeekWeekPattern?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
serviceorterritoryis 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
dateDateTimeThe date whose date component is resolved.
serviceINotableDateServiceThe service used to resolve notable dates.
territorystringThe requested territory code.
filterNotableDateFilterAn optional filter the occurrences must satisfy.
Returns
- IReadOnlyList<NotableDate>
The emitted occurrences; empty when there are none.
Exceptions
- ArgumentNullException
serviceorterritoryis 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
dateDateTimeThe date whose date component is tested.
serviceINotableDateServiceThe service used to resolve notable dates.
territorystringThe requested territory code.
workingWeekWeekPattern?The working-week pattern, or null for Monday to Friday.
Returns
Exceptions
- ArgumentNullException
serviceorterritoryis 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
dateDateTimeThe date whose date component is tested.
serviceINotableDateServiceThe service used to resolve notable dates.
territorystringThe requested territory code.
filterNotableDateFilterAn optional filter the occurrence must satisfy.
Returns
Exceptions
- ArgumentNullException
serviceorterritoryis null.
IsWeekend(DateTime, WeekPattern?)
Determines whether the date falls outside the working week.
public static bool IsWeekend(this DateTime date, WeekPattern? workingWeek = null)
Parameters
dateDateTimeThe date whose date component is tested.
workingWeekWeekPattern?The working-week pattern, or null for Monday to Friday.
Returns
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
dateDateTimeThe date whose date component is tested.
serviceINotableDateServiceThe service used to resolve notable dates.
territorystringThe requested territory code.
workingWeekWeekPattern?The working-week pattern, or null for Monday to Friday.
Returns
Exceptions
- ArgumentNullException
serviceorterritoryis 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
dateDateTimeThe starting date.
serviceINotableDateServiceThe service used to resolve notable dates.
territorystringThe requested territory code.
workingWeekWeekPattern?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
serviceorterritoryis 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
dateDateTimeThe reference date whose date component is used.
serviceINotableDateServiceThe service used to resolve notable dates.
territorystringThe requested territory code.
filterNotableDateFilterAn optional filter the occurrence must satisfy.
Returns
- NotableDate
The next matching occurrence, or null when none exists up to the maximum year.
Exceptions
- ArgumentNullException
serviceorterritoryis 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
dateDateTimeThe starting date.
serviceINotableDateServiceThe service used to resolve notable dates.
territorystringThe requested territory code.
workingWeekWeekPattern?The working-week pattern, or null for Monday to Friday.
Returns
- DateTime
The next working day at the original time-of-day.
Exceptions
- ArgumentNullException
serviceorterritoryis 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
dateDateTimeThe starting date.
serviceINotableDateServiceThe service used to resolve notable dates.
territorystringThe requested territory code.
workingWeekWeekPattern?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
serviceorterritoryis 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
dateDateTimeThe reference date whose date component is used.
serviceINotableDateServiceThe service used to resolve notable dates.
territorystringThe requested territory code.
filterNotableDateFilterAn optional filter the occurrence must satisfy.
Returns
- NotableDate
The previous matching occurrence, or null when none exists down to the minimum year.
Exceptions
- ArgumentNullException
serviceorterritoryis 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
dateDateTimeThe starting date.
serviceINotableDateServiceThe service used to resolve notable dates.
territorystringThe requested territory code.
workingWeekWeekPattern?The working-week pattern, or null for Monday to Friday.
Returns
- DateTime
The previous working day at the original time-of-day.
Exceptions
- ArgumentNullException
serviceorterritoryis 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
dateDateTimeThe date to snap.
serviceINotableDateServiceThe service used to resolve notable dates.
territorystringThe requested territory code.
workingWeekWeekPattern?The working-week pattern, or null for Monday to Friday.
Returns
- DateTime
The nearest working day at the original time-of-day.
Exceptions
- ArgumentNullException
serviceorterritoryis 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
dateDateTimeThe date to snap.
serviceINotableDateServiceThe service used to resolve notable dates.
territorystringThe requested territory code.
workingWeekWeekPattern?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
serviceorterritoryis 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
dateDateTimeThe date to snap.
serviceINotableDateServiceThe service used to resolve notable dates.
territorystringThe requested territory code.
workingWeekWeekPattern?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
serviceorterritoryis 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
startDateTimeOne end of the range.
endDateTimeThe other end of the range.
serviceINotableDateServiceThe service used to resolve notable dates.
territorystringThe requested territory code.
workingWeekWeekPattern?The working-week pattern, or null for Monday to Friday.
Returns
- int
The number of working days in the inclusive range.
Exceptions
- ArgumentNullException
serviceorterritoryis null.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |