NotableDateOnlyExtensions 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 DateOnly, resolved through an explicit INotableDateService for a requested territory.
public static class NotableDateOnlyExtensions
- Inheritance
-
NotableDateOnlyExtensions
- Inherited Members
Examples
INotableDateService service = AmericasCalendarData.CreateService("US");
DateOnly date = new(2026, 7, 3); // Friday, observed Independence Day in the US
// Is this a working day?
bool working = date.IsWorkingDay(service, "US"); // false
// Settlement date three working days out, skipping weekends and holidays.
DateOnly settles = date.AddWorkingDays(3, service, "US");
// The next working day on or after a candidate date.
DateOnly resume = date.SnapToWorkingDay(service, "US");
// Every notable date in July 2026.
IReadOnlyList<NotableDate> july = date.GetNotableDatesInMonth(service, "US");
Remarks
A working day is a day that is neither outside the working week nor a non-working notable date. The working week defaults to Monday through Friday and can be overridden with a WeekPattern. The traversal and counting methods resolve each candidate day through the service, so prefer the range-based EnumerateNotableDates(DateOnly, DateOnly, INotableDateService, string, NotableDateFilter?) for large windows.
Method groups. IsWeekend / IsWorkingDay / IsNonWorkingDay /
IsNotableDate test a single day; NextWorkingDay / PreviousWorkingDay / SnapToWorkingDay
(and the NonWorkingDay / NotableDate variants) traverse to a nearby day; AddWorkingDays /
WorkingDaysBetween count working days; and EnumerateWorkingDays / EnumerateNonWorkingDays /
EnumerateNotableDates stream a window.
Methods
AddWorkingDays(DateOnly, int, INotableDateService, string, WeekPattern?)
Advances the date by a signed number of working days.
public static DateOnly AddWorkingDays(this DateOnly date, int count, INotableDateService service, string territory, WeekPattern? workingWeek = null)
Parameters
dateDateOnlyThe 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
- DateOnly
The resulting date.
Examples
INotableDateService service = AmericasCalendarData.CreateService("US");
// A T+2 settlement date that skips weekends and US holidays.
DateOnly trade = new(2026, 7, 2);
DateOnly settles = trade.AddWorkingDays(2, service, "US"); // jumps past July 4th observance
Exceptions
- ArgumentNullException
serviceorterritoryis null.
EnumerateNonWorkingDays(DateOnly, DateOnly, INotableDateService, string, WeekPattern?)
Lazily enumerates the non-working days in the inclusive range, in ascending order.
public static IEnumerable<DateOnly> EnumerateNonWorkingDays(this DateOnly start, DateOnly end, INotableDateService service, string territory, WeekPattern? workingWeek = null)
Parameters
startDateOnlyThe inclusive start date.
endDateOnlyThe 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<DateOnly>
The non-working days in the range.
Examples
INotableDateService service = AsiaPacificCalendarData.CreateService("AU");
// Anzac week 2024: the weekend plus Anzac Day (Thursday 25 April).
foreach (DateOnly closed in new DateOnly(2024, 4, 22).EnumerateNonWorkingDays(
new DateOnly(2024, 4, 28), service, "AU"))
{
// 2024-04-25, 2024-04-27, 2024-04-28
}
Exceptions
- ArgumentNullException
serviceorterritoryis null.
EnumerateNotableDates(DateOnly, DateOnly, INotableDateService, string, NotableDateFilter?)
Resolves the notable dates emitted within the inclusive range for the territory.
public static IReadOnlyList<NotableDate> EnumerateNotableDates(this DateOnly start, DateOnly end, INotableDateService service, string territory, NotableDateFilter? filter = null)
Parameters
startDateOnlyThe inclusive start date.
endDateOnlyThe 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.
Examples
INotableDateService service = AsiaPacificCalendarData.CreateService("AU");
// Every public holiday in January 2026, eagerly materialized.
IReadOnlyList<NotableDate> january = new DateOnly(2026, 1, 1).EnumerateNotableDates(
new DateOnly(2026, 1, 31), service, "AU",
NotableDateFilter.ForCategory(NotableDateCategory.PublicHoliday));
Exceptions
- ArgumentNullException
serviceorterritoryis null.
EnumerateWorkingDays(DateOnly, DateOnly, INotableDateService, string, WeekPattern?)
Lazily enumerates the working days in the inclusive range, in ascending order.
public static IEnumerable<DateOnly> EnumerateWorkingDays(this DateOnly start, DateOnly end, INotableDateService service, string territory, WeekPattern? workingWeek = null)
Parameters
startDateOnlyThe inclusive start date.
endDateOnlyThe 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<DateOnly>
The working days in the range.
Examples
INotableDateService service = AmericasCalendarData.CreateService("US");
// Iterate the working days of July 2026, skipping weekends and holidays.
foreach (DateOnly day in new DateOnly(2026, 7, 1).EnumerateWorkingDays(new DateOnly(2026, 7, 31), service, "US"))
Console.WriteLine(day);
Exceptions
- ArgumentNullException
serviceorterritoryis null.
GetNotableDates(DateOnly, INotableDateService, string, NotableDateFilter?)
Gets the notable dates emitted on the date for the territory.
public static IReadOnlyList<NotableDate> GetNotableDates(this DateOnly date, INotableDateService service, string territory, NotableDateFilter? filter = null)
Parameters
dateDateOnlyThe date to resolve.
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.
Examples
INotableDateService service = AmericasCalendarData.CreateService("US");
IReadOnlyList<NotableDate> occurrences = new DateOnly(2026, 12, 25).GetNotableDates(service, "US");
foreach (NotableDate notable in occurrences)
Console.WriteLine(notable.DisplayName);
Exceptions
- ArgumentNullException
serviceorterritoryis null.
GetNotableDatesInMonth(DateOnly, INotableDateService, string, NotableDateFilter?)
Resolves the notable dates emitted in the calendar month that contains the date for the territory.
public static IReadOnlyList<NotableDate> GetNotableDatesInMonth(this DateOnly date, INotableDateService service, string territory, NotableDateFilter? filter = null)
Parameters
dateDateOnlyA date within the month to resolve.
serviceINotableDateServiceThe service used to resolve notable dates.
territorystringThe requested territory code.
filterNotableDateFilterAn optional filter the occurrences must satisfy.
Returns
- IReadOnlyList<NotableDate>
The emitted occurrences in the month, ordered by date then identity.
Examples
INotableDateService service = AmericasCalendarData.CreateService("US");
// Every notable date in December 2026, derived from any date within the month.
IReadOnlyList<NotableDate> month = new DateOnly(2026, 12, 15).GetNotableDatesInMonth(service, "US");
Exceptions
- ArgumentNullException
serviceorterritoryis null.
GetNotableDatesInYear(DateOnly, INotableDateService, string, NotableDateFilter?)
Resolves the notable dates emitted in the calendar year that contains the date for the territory.
public static IReadOnlyList<NotableDate> GetNotableDatesInYear(this DateOnly date, INotableDateService service, string territory, NotableDateFilter? filter = null)
Parameters
dateDateOnlyA date within the year to resolve.
serviceINotableDateServiceThe service used to resolve notable dates.
territorystringThe requested territory code.
filterNotableDateFilterAn optional filter the occurrences must satisfy.
Returns
- IReadOnlyList<NotableDate>
The emitted occurrences in the year, ordered by date then identity.
Examples
INotableDateService service = AmericasCalendarData.CreateService("US");
// Every notable date in 2026, derived from any date within the year.
IReadOnlyList<NotableDate> year = new DateOnly(2026, 1, 1).GetNotableDatesInYear(service, "US");
Exceptions
- ArgumentNullException
serviceorterritoryis null.
IsNonWorkingDay(DateOnly, INotableDateService, string, WeekPattern?)
Determines whether the date is a non-working day: outside the working week, or a non-working notable date.
public static bool IsNonWorkingDay(this DateOnly date, INotableDateService service, string territory, WeekPattern? workingWeek = null)
Parameters
dateDateOnlyThe date to test.
serviceINotableDateServiceThe service used to resolve notable dates.
territorystringThe requested territory code.
workingWeekWeekPattern?The working-week pattern, or null for Monday to Friday.
Returns
Examples
INotableDateService service = AsiaPacificCalendarData.CreateService("AU");
bool anzacDay = new DateOnly(2024, 4, 25).IsNonWorkingDay(service, "AU"); // true (public holiday)
bool friday = new DateOnly(2024, 4, 26).IsNonWorkingDay(service, "AU"); // false
Exceptions
- ArgumentNullException
serviceorterritoryis null.
IsNotableDate(DateOnly, INotableDateService, string, NotableDateFilter?)
Determines whether any notable date is emitted on the date for the territory.
public static bool IsNotableDate(this DateOnly date, INotableDateService service, string territory, NotableDateFilter? filter = null)
Parameters
dateDateOnlyThe date to test.
serviceINotableDateServiceThe service used to resolve notable dates.
territorystringThe requested territory code.
filterNotableDateFilterAn optional filter the occurrence must satisfy.
Returns
Examples
INotableDateService service = AmericasCalendarData.CreateService("US");
bool isHoliday = new DateOnly(2026, 7, 4).IsNotableDate(service, "US"); // true (Independence Day)
Exceptions
- ArgumentNullException
serviceorterritoryis null.
IsWeekend(DateOnly, WeekPattern?)
Determines whether the date falls outside the working week.
public static bool IsWeekend(this DateOnly date, WeekPattern? workingWeek = null)
Parameters
dateDateOnlyThe date to test.
workingWeekWeekPattern?The working-week pattern, or null for Monday to Friday.
Returns
Examples
bool saturday = new DateOnly(2026, 1, 3).IsWeekend(); // true under the default Mon-Fri week
// A Sunday-Thursday working week makes Friday the weekend instead.
var sundayToThursday = new WeekPattern(
DayOfWeek.Sunday, DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday);
bool friday = new DateOnly(2026, 1, 2).IsWeekend(sundayToThursday); // true
IsWorkingDay(DateOnly, INotableDateService, string, WeekPattern?)
Determines whether the date is a working day.
public static bool IsWorkingDay(this DateOnly date, INotableDateService service, string territory, WeekPattern? workingWeek = null)
Parameters
dateDateOnlyThe date to test.
serviceINotableDateServiceThe service used to resolve notable dates.
territorystringThe requested territory code.
workingWeekWeekPattern?The working-week pattern, or null for Monday to Friday.
Returns
Examples
INotableDateService service = AmericasCalendarData.CreateService("US");
bool labourDay = new DateOnly(2026, 9, 7).IsWorkingDay(service, "US"); // false (Labor Day)
bool ordinary = new DateOnly(2026, 9, 8).IsWorkingDay(service, "US"); // true
Exceptions
- ArgumentNullException
serviceorterritoryis null.
NextNonWorkingDay(DateOnly, INotableDateService, string, WeekPattern?)
Returns the first non-working day strictly after the date.
public static DateOnly NextNonWorkingDay(this DateOnly date, INotableDateService service, string territory, WeekPattern? workingWeek = null)
Parameters
dateDateOnlyThe 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
- DateOnly
The next non-working day.
Examples
INotableDateService service = AsiaPacificCalendarData.CreateService("AU");
// From Monday 22 April 2024 the next closed day is Anzac Day, before the weekend.
DateOnly closed = new DateOnly(2024, 4, 22).NextNonWorkingDay(service, "AU"); // 2024-04-25
Exceptions
- ArgumentNullException
serviceorterritoryis null.- InvalidOperationException
No non-working day is found within the traversal guard.
NextNotableDate(DateOnly, INotableDateService, string, NotableDateFilter?)
Returns the earliest notable date emitted strictly after the date for the territory.
public static NotableDate? NextNotableDate(this DateOnly date, INotableDateService service, string territory, NotableDateFilter? filter = null)
Parameters
dateDateOnlyThe reference date.
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.
Examples
INotableDateService service = AmericasCalendarData.CreateService("US");
// The next public holiday after today.
NotableDate? upcoming = DateOnly.FromDateTime(DateTime.Today).NextNotableDate(service, "US");
if (upcoming is not null)
Console.WriteLine($"{upcoming.DisplayName} on {upcoming.Date}");
Exceptions
- ArgumentNullException
serviceorterritoryis null.
NextWorkingDay(DateOnly, INotableDateService, string, WeekPattern?)
Returns the first working day strictly after the date.
public static DateOnly NextWorkingDay(this DateOnly date, INotableDateService service, string territory, WeekPattern? workingWeek = null)
Parameters
dateDateOnlyThe 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
- DateOnly
The next working day.
Examples
INotableDateService service = AmericasCalendarData.CreateService("US");
// The first business day after a holiday weekend.
DateOnly resume = new DateOnly(2026, 7, 3).NextWorkingDay(service, "US");
Exceptions
- ArgumentNullException
serviceorterritoryis null.
PreviousNonWorkingDay(DateOnly, INotableDateService, string, WeekPattern?)
Returns the first non-working day strictly before the date.
public static DateOnly PreviousNonWorkingDay(this DateOnly date, INotableDateService service, string territory, WeekPattern? workingWeek = null)
Parameters
dateDateOnlyThe 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
- DateOnly
The previous non-working day.
Examples
INotableDateService service = AsiaPacificCalendarData.CreateService("AU");
// From Monday 29 April 2024 the most recent closed day is the Sunday before.
DateOnly closed = new DateOnly(2024, 4, 29).PreviousNonWorkingDay(service, "AU"); // 2024-04-28
Exceptions
- ArgumentNullException
serviceorterritoryis null.- InvalidOperationException
No non-working day is found within the traversal guard.
PreviousNotableDate(DateOnly, INotableDateService, string, NotableDateFilter?)
Returns the most recent notable date emitted strictly before the date for the territory.
public static NotableDate? PreviousNotableDate(this DateOnly date, INotableDateService service, string territory, NotableDateFilter? filter = null)
Parameters
dateDateOnlyThe reference date.
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.
Examples
INotableDateService service = AsiaPacificCalendarData.CreateService("AU");
// The most recent public holiday before 1 May 2024 is Anzac Day.
NotableDate? previous = new DateOnly(2024, 5, 1).PreviousNotableDate(
service, "AU", NotableDateFilter.ForCategory(NotableDateCategory.PublicHoliday));
// previous?.Date == 2024-04-25
Exceptions
- ArgumentNullException
serviceorterritoryis null.
PreviousWorkingDay(DateOnly, INotableDateService, string, WeekPattern?)
Returns the first working day strictly before the date.
public static DateOnly PreviousWorkingDay(this DateOnly date, INotableDateService service, string territory, WeekPattern? workingWeek = null)
Parameters
dateDateOnlyThe 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
- DateOnly
The previous working day.
Examples
INotableDateService service = AsiaPacificCalendarData.CreateService("AU");
// From Friday 26 April 2024 the previous open day skips Anzac Day back to Wednesday.
DateOnly open = new DateOnly(2024, 4, 26).PreviousWorkingDay(service, "AU"); // 2024-04-24
Exceptions
- ArgumentNullException
serviceorterritoryis null.
SnapToNearestWorkingDay(DateOnly, INotableDateService, string, WeekPattern?)
Returns the date if it is a working day; otherwise the nearest working day, preferring the forward direction on a tie.
public static DateOnly SnapToNearestWorkingDay(this DateOnly date, INotableDateService service, string territory, WeekPattern? workingWeek = null)
Parameters
dateDateOnlyThe 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
- DateOnly
The nearest working day.
Examples
INotableDateService service = AsiaPacificCalendarData.CreateService("AU");
// Saturday 27 April 2024 snaps back to Friday (one day) rather than forward to Monday (two).
DateOnly nearest = new DateOnly(2024, 4, 27).SnapToNearestWorkingDay(service, "AU"); // 2024-04-26
// A working day is returned unchanged.
DateOnly noOp = new DateOnly(2024, 4, 23).SnapToNearestWorkingDay(service, "AU"); // 2024-04-23
Exceptions
- ArgumentNullException
serviceorterritoryis null.
SnapToWorkingDay(DateOnly, INotableDateService, string, WeekPattern?)
Returns the date if it is a working day; otherwise the next working day.
public static DateOnly SnapToWorkingDay(this DateOnly date, INotableDateService service, string territory, WeekPattern? workingWeek = null)
Parameters
dateDateOnlyThe 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
- DateOnly
The date or the next working day.
Examples
INotableDateService service = AmericasCalendarData.CreateService("US");
// Roll a scheduled due date forward to the next working day when it lands on a holiday.
DateOnly due = new DateOnly(2026, 7, 4).SnapToWorkingDay(service, "US");
Exceptions
- ArgumentNullException
serviceorterritoryis null.
SnapToWorkingDayBackward(DateOnly, INotableDateService, string, WeekPattern?)
Returns the date if it is a working day; otherwise the previous working day.
public static DateOnly SnapToWorkingDayBackward(this DateOnly date, INotableDateService service, string territory, WeekPattern? workingWeek = null)
Parameters
dateDateOnlyThe 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
- DateOnly
The date or the previous working day.
Examples
INotableDateService service = AsiaPacificCalendarData.CreateService("AU");
// A "no later than" contractual date falling on Anzac Day rolls back to Wednesday.
DateOnly payday = new DateOnly(2024, 4, 25).SnapToWorkingDayBackward(service, "AU"); // 2024-04-24
Exceptions
- ArgumentNullException
serviceorterritoryis null.
WorkingDaysBetween(DateOnly, DateOnly, 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 DateOnly start, DateOnly end, INotableDateService service, string territory, WeekPattern? workingWeek = null)
Parameters
startDateOnlyOne end of the range.
endDateOnlyThe 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.
Examples
INotableDateService service = AmericasCalendarData.CreateService("US");
// Billable working days across a project window, excluding weekends and holidays.
int days = new DateOnly(2026, 7, 1).WorkingDaysBetween(new DateOnly(2026, 7, 31), service, "US");
Exceptions
- ArgumentNullException
serviceorterritoryis null.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |