NotableDateTimeOffsetExtensions 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 DateTimeOffset, delegating to the DateOnly surface on the offset-local date component.
public static class NotableDateTimeOffsetExtensions
- Inheritance
-
NotableDateTimeOffsetExtensions
- Inherited Members
Examples
INotableDateService service = AmericasCalendarData.CreateService("US");
DateTimeOffset stamp = new(2026, 7, 3, 14, 0, 0, TimeSpan.FromHours(-5)); // observed Independence Day
bool working = stamp.IsWorkingDay(service, "US"); // false
// The next working day keeps the original time-of-day and -05:00 offset.
DateTimeOffset resume = stamp.NextWorkingDay(service, "US");
Remarks
The date component is the offset-local wall-clock date (DateTime). Traversal methods that return a moved DateTimeOffset preserve the original time-of-day and Offset.
Methods
AddWorkingDays(DateTimeOffset, int, INotableDateService, string, WeekPattern?)
Advances the date by a signed number of working days, preserving the time-of-day and offset.
public static DateTimeOffset AddWorkingDays(this DateTimeOffset date, int count, INotableDateService service, string territory, WeekPattern? workingWeek = null)
Parameters
dateDateTimeOffsetThe 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
- DateTimeOffset
The resulting date at the original time-of-day and offset.
Exceptions
- ArgumentNullException
serviceorterritoryis null.
EnumerateNotableDates(DateTimeOffset, DateTimeOffset, INotableDateService, string, NotableDateFilter?)
Resolves the notable dates emitted within the inclusive range for the territory.
public static IReadOnlyList<NotableDate> EnumerateNotableDates(this DateTimeOffset start, DateTimeOffset end, INotableDateService service, string territory, NotableDateFilter? filter = null)
Parameters
startDateTimeOffsetThe inclusive start date.
endDateTimeOffsetThe 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(DateTimeOffset, DateTimeOffset, INotableDateService, string, WeekPattern?)
Lazily enumerates the working days in the inclusive range, in ascending order, each at the start's time-of-day and offset.
public static IEnumerable<DateTimeOffset> EnumerateWorkingDays(this DateTimeOffset start, DateTimeOffset end, INotableDateService service, string territory, WeekPattern? workingWeek = null)
Parameters
startDateTimeOffsetThe inclusive start date.
endDateTimeOffsetThe 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<DateTimeOffset>
The working days in the range at the start's time-of-day and offset.
Exceptions
- ArgumentNullException
serviceorterritoryis null.
GetNotableDates(DateTimeOffset, INotableDateService, string, NotableDateFilter?)
Gets the notable dates emitted on the date for the territory.
public static IReadOnlyList<NotableDate> GetNotableDates(this DateTimeOffset date, INotableDateService service, string territory, NotableDateFilter? filter = null)
Parameters
dateDateTimeOffsetThe value whose offset-local date 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(DateTimeOffset, INotableDateService, string, WeekPattern?)
Determines whether the date is a non-working day for the territory.
public static bool IsNonWorkingDay(this DateTimeOffset date, INotableDateService service, string territory, WeekPattern? workingWeek = null)
Parameters
dateDateTimeOffsetThe value whose offset-local date 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(DateTimeOffset, INotableDateService, string, NotableDateFilter?)
Determines whether any notable date is emitted on the date for the territory.
public static bool IsNotableDate(this DateTimeOffset date, INotableDateService service, string territory, NotableDateFilter? filter = null)
Parameters
dateDateTimeOffsetThe value whose offset-local date 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(DateTimeOffset, WeekPattern?)
Determines whether the date falls outside the working week.
public static bool IsWeekend(this DateTimeOffset date, WeekPattern? workingWeek = null)
Parameters
dateDateTimeOffsetThe value whose offset-local date is tested.
workingWeekWeekPattern?The working-week pattern, or null for Monday to Friday.
Returns
IsWorkingDay(DateTimeOffset, INotableDateService, string, WeekPattern?)
Determines whether the date is a working day for the territory.
public static bool IsWorkingDay(this DateTimeOffset date, INotableDateService service, string territory, WeekPattern? workingWeek = null)
Parameters
dateDateTimeOffsetThe value whose offset-local date 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.
NextWorkingDay(DateTimeOffset, INotableDateService, string, WeekPattern?)
Returns the first working day strictly after the date, preserving the time-of-day and offset.
public static DateTimeOffset NextWorkingDay(this DateTimeOffset date, INotableDateService service, string territory, WeekPattern? workingWeek = null)
Parameters
dateDateTimeOffsetThe 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
- DateTimeOffset
The next working day at the original time-of-day and offset.
Exceptions
- ArgumentNullException
serviceorterritoryis null.
PreviousWorkingDay(DateTimeOffset, INotableDateService, string, WeekPattern?)
Returns the first working day strictly before the date, preserving the time-of-day and offset.
public static DateTimeOffset PreviousWorkingDay(this DateTimeOffset date, INotableDateService service, string territory, WeekPattern? workingWeek = null)
Parameters
dateDateTimeOffsetThe 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
- DateTimeOffset
The previous working day at the original time-of-day and offset.
Exceptions
- ArgumentNullException
serviceorterritoryis null.
SnapToNearestWorkingDay(DateTimeOffset, INotableDateService, string, WeekPattern?)
Returns the date if it is a working day; otherwise the nearest working day, preserving the time-of-day and offset.
public static DateTimeOffset SnapToNearestWorkingDay(this DateTimeOffset date, INotableDateService service, string territory, WeekPattern? workingWeek = null)
Parameters
dateDateTimeOffsetThe 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
- DateTimeOffset
The nearest working day at the original time-of-day and offset.
Exceptions
- ArgumentNullException
serviceorterritoryis null.
SnapToWorkingDay(DateTimeOffset, INotableDateService, string, WeekPattern?)
Returns the date if it is a working day; otherwise the next working day, preserving the time-of-day and offset.
public static DateTimeOffset SnapToWorkingDay(this DateTimeOffset date, INotableDateService service, string territory, WeekPattern? workingWeek = null)
Parameters
dateDateTimeOffsetThe 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
- DateTimeOffset
The date or the next working day, at the original time-of-day and offset.
Exceptions
- ArgumentNullException
serviceorterritoryis null.
SnapToWorkingDayBackward(DateTimeOffset, INotableDateService, string, WeekPattern?)
Returns the date if it is a working day; otherwise the previous working day, preserving the time-of-day and offset.
public static DateTimeOffset SnapToWorkingDayBackward(this DateTimeOffset date, INotableDateService service, string territory, WeekPattern? workingWeek = null)
Parameters
dateDateTimeOffsetThe 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
- DateTimeOffset
The date or the previous working day, at the original time-of-day and offset.
Exceptions
- ArgumentNullException
serviceorterritoryis null.
WorkingDaysBetween(DateTimeOffset, DateTimeOffset, 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 DateTimeOffset start, DateTimeOffset end, INotableDateService service, string territory, WeekPattern? workingWeek = null)
Parameters
startDateTimeOffsetOne end of the range.
endDateTimeOffsetThe 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 |