Table of Contents

Class DateTimeRangeExtensions

Namespace
HeroKit.DateTimes
Assembly
HeroKit.dll

Provides range, boundary and age helpers for DateTime and DateOnly values.

public static class DateTimeRangeExtensions
Inheritance
DateTimeRangeExtensions
Inherited Members

Methods

Age(DateOnly, DateOnly)

Calculates the completed years between a birth date and a reference date. A Feb 29 birthday counts as completed on Mar 1 in non-leap years.

public static int Age(this DateOnly birthDate, DateOnly asOf)

Parameters

birthDate DateOnly

The birth date.

asOf DateOnly

The reference date.

Returns

int

The number of completed years.

Examples

new DateOnly(2000, 2, 29).Age(new DateOnly(2026, 3, 1)); // 26

Exceptions

ArgumentOutOfRangeException

Thrown when asOf is earlier than birthDate.

Age(DateTime, DateTime)

Calculates the completed years between a birth date and a reference date. A Feb 29 birthday counts as completed on Mar 1 in non-leap years.

public static int Age(this DateTime birthDate, DateTime asOf)

Parameters

birthDate DateTime

The birth date.

asOf DateTime

The reference date.

Returns

int

The number of completed years.

Examples

new DateTime(1990, 5, 20).Age(new DateTime(2026, 5, 19)); // 35

Exceptions

ArgumentOutOfRangeException

Thrown when asOf is earlier than birthDate.

EndOfDay(DateTime)

Returns the last tick of the day and keeps the DateTimeKind.

public static DateTime EndOfDay(this DateTime value)

Parameters

value DateTime

The date and time.

Returns

DateTime

The last tick of the day.

Examples

new DateTime(2026, 3, 7, 14, 5, 9).EndOfDay(); // 2026-03-07 23:59:59.9999999

EndOfMonth(DateOnly)

Returns the last day of the month.

public static DateOnly EndOfMonth(this DateOnly value)

Parameters

value DateOnly

The date.

Returns

DateOnly

The last day of the month.

Examples

new DateOnly(2024, 2, 10).EndOfMonth(); // 2024-02-29

EndOfMonth(DateTime)

Returns the last tick of the month and keeps the DateTimeKind.

public static DateTime EndOfMonth(this DateTime value)

Parameters

value DateTime

The date and time.

Returns

DateTime

The last tick of the month.

Examples

new DateTime(2024, 2, 10).EndOfMonth(); // 2024-02-29 23:59:59.9999999

EndOfWeek(DateOnly)

Returns the end of the week (last day of the week) for a date.

public static DateOnly EndOfWeek(this DateOnly value)

Parameters

value DateOnly

The date.

Returns

DateOnly

The last day of the week (Monday start).

Examples

new DateOnly(2026, 3, 7).EndOfWeek(); // 2026-03-08

EndOfWeek(DateOnly, DayOfWeek)

Returns the last day of the week for a date.

public static DateOnly EndOfWeek(this DateOnly value, DayOfWeek firstDayOfWeek)

Parameters

value DateOnly

The date.

firstDayOfWeek DayOfWeek

The day that starts the week.

Returns

DateOnly

The last day of the week.

Examples

new DateOnly(2026, 3, 7).EndOfWeek(DayOfWeek.Sunday);

EndOfWeek(DateTime)

Returns the last tick of the week (Sunday) and keeps the DateTimeKind.

public static DateTime EndOfWeek(this DateTime value)

Parameters

value DateTime

The date and time.

Returns

DateTime

The last tick of the week.

Examples

new DateTime(2026, 3, 7).EndOfWeek(); // 2026-03-08 23:59:59.9999999 (Sunday)

EndOfWeek(DateTime, DayOfWeek)

Returns the last tick of the week for the given first day of the week and keeps the DateTimeKind.

public static DateTime EndOfWeek(this DateTime value, DayOfWeek firstDayOfWeek)

Parameters

value DateTime

The date and time.

firstDayOfWeek DayOfWeek

The day that starts the week.

Returns

DateTime

The last tick of the week.

Examples

new DateTime(2026, 3, 7).EndOfWeek(DayOfWeek.Sunday);

EndOfYear(DateTime)

Returns the last tick of the year and keeps the DateTimeKind.

public static DateTime EndOfYear(this DateTime value)

Parameters

value DateTime

The date and time.

Returns

DateTime

The last tick of the year.

Examples

new DateTime(2026, 3, 7).EndOfYear(); // 2026-12-31 23:59:59.9999999

IsBetween(DateOnly, DateOnly, DateOnly)

Determines whether the date lies between start and end, both ends included.

public static bool IsBetween(this DateOnly value, DateOnly start, DateOnly end)

Parameters

value DateOnly

The date to test.

start DateOnly

The lower bound.

end DateOnly

The upper bound.

Returns

bool

true if start <= value <= end.

Examples

new DateOnly(2026, 3, 7).IsBetween(new DateOnly(2026, 3, 1), new DateOnly(2026, 3, 7)); // true

Exceptions

ArgumentException

Thrown when start is later than end.

IsBetween(DateTime, DateTime, DateTime)

Determines whether the value lies between start and end, both ends included.

public static bool IsBetween(this DateTime value, DateTime start, DateTime end)

Parameters

value DateTime

The date and time to test.

start DateTime

The lower bound.

end DateTime

The upper bound.

Returns

bool

true if start <= value <= end.

Examples

new DateTime(2026, 3, 7).IsBetween(new DateTime(2026, 3, 1), new DateTime(2026, 3, 7)); // true

Exceptions

ArgumentException

Thrown when start is later than end.

IsWeekend(DateOnly)

Determines whether the date falls on a Saturday or Sunday.

public static bool IsWeekend(this DateOnly value)

Parameters

value DateOnly

The date.

Returns

bool

true for Saturday and Sunday; otherwise false.

Examples

new DateOnly(2026, 3, 7).IsWeekend(); // true

IsWeekend(DateTime)

Determines whether the date falls on a Saturday or Sunday.

public static bool IsWeekend(this DateTime value)

Parameters

value DateTime

The date and time.

Returns

bool

true for Saturday and Sunday; otherwise false.

Examples

new DateTime(2026, 3, 7).IsWeekend(); // true (Saturday)

StartOfDay(DateTime)

Returns the start of the day (00:00:00) and keeps the DateTimeKind.

public static DateTime StartOfDay(this DateTime value)

Parameters

value DateTime

The date and time.

Returns

DateTime

The first tick of the day.

Examples

new DateTime(2026, 3, 7, 14, 5, 9).StartOfDay(); // 2026-03-07 00:00:00

StartOfMonth(DateOnly)

Returns the first day of the month.

public static DateOnly StartOfMonth(this DateOnly value)

Parameters

value DateOnly

The date.

Returns

DateOnly

The first day of the month.

Examples

new DateOnly(2026, 3, 7).StartOfMonth(); // 2026-03-01

StartOfMonth(DateTime)

Returns the start of the month and keeps the DateTimeKind.

public static DateTime StartOfMonth(this DateTime value)

Parameters

value DateTime

The date and time.

Returns

DateTime

The first tick of the month.

Examples

new DateTime(2026, 3, 7).StartOfMonth(); // 2026-03-01 00:00:00

StartOfWeek(DateOnly)

Returns the start of the week (first day of the week) for a date.

public static DateOnly StartOfWeek(this DateOnly value)

Parameters

value DateOnly

The date.

Returns

DateOnly

The first day of the week (Monday start).

Examples

new DateOnly(2026, 3, 7).StartOfWeek(); // 2026-03-02

StartOfWeek(DateOnly, DayOfWeek)

Returns the first day of the week for a date.

public static DateOnly StartOfWeek(this DateOnly value, DayOfWeek firstDayOfWeek)

Parameters

value DateOnly

The date.

firstDayOfWeek DayOfWeek

The day that starts the week.

Returns

DateOnly

The first day of the week.

Examples

new DateOnly(2026, 3, 7).StartOfWeek(DayOfWeek.Sunday);

StartOfWeek(DateTime)

Returns the start of the week (Monday, 00:00:00) and keeps the DateTimeKind.

public static DateTime StartOfWeek(this DateTime value)

Parameters

value DateTime

The date and time.

Returns

DateTime

The first tick of the week.

Examples

new DateTime(2026, 3, 7).StartOfWeek(); // 2026-03-02 (Monday)

StartOfWeek(DateTime, DayOfWeek)

Returns the first tick of the week for the given first day of the week and keeps the DateTimeKind.

public static DateTime StartOfWeek(this DateTime value, DayOfWeek firstDayOfWeek)

Parameters

value DateTime

The date and time.

firstDayOfWeek DayOfWeek

The day that starts the week.

Returns

DateTime

The first tick of the week.

Examples

new DateTime(2026, 3, 7).StartOfWeek(DayOfWeek.Sunday);

StartOfYear(DateTime)

Returns the start of the year and keeps the DateTimeKind.

public static DateTime StartOfYear(this DateTime value)

Parameters

value DateTime

The date and time.

Returns

DateTime

The first tick of the year.

Examples

new DateTime(2026, 3, 7).StartOfYear(); // 2026-01-01 00:00:00