Table of Contents

Class DateTimeExtensions

Namespace
Ddth.Utilities.Tempus
Assembly
Ddth.Utilities.dll

Extensions that provide utility methods for the DateTime struct.

public static class DateTimeExtensions
Inheritance
DateTimeExtensions
Inherited Members

Methods

IsOnDayOfWeek(DateTime, IEnumerable<DayOfWeek>)

Checks if the day of week component of the given DateTime falls on any of the specified days of week.

public static bool IsOnDayOfWeek(this DateTime dateTime, IEnumerable<DayOfWeek> dows)

Parameters

dateTime DateTime
dows IEnumerable<DayOfWeek>

Returns

bool

IsOnDayOfWeek(DateTime, IEnumerable<string>)

Checks if the day of week component of the given DateTime falls on any of the specified days of week (case-insensitive, supports both full and abbreviated day of week names).

public static bool IsOnDayOfWeek(this DateTime dateTime, IEnumerable<string> dows)

Parameters

dateTime DateTime
dows IEnumerable<string>

Returns

bool

IsOnDayOfWeek(DateTime, params DayOfWeek[])

Checks if the day of week component of the given DateTime falls on any of the specified days of week.

public static bool IsOnDayOfWeek(this DateTime dateTime, params DayOfWeek[] dows)

Parameters

dateTime DateTime
dows DayOfWeek[]

Returns

bool

IsOnDayOfWeek(DateTime, params string[])

Checks if the day of week component of the given DateTime falls on any of the specified days of week (case-insensitive, supports both full and abbreviated day of week names).

public static bool IsOnDayOfWeek(this DateTime dateTime, params string[] dows)

Parameters

dateTime DateTime
dows string[]

Returns

bool

IsWithinTimeWindow(DateTime, TimeOnly, TimeOnly)

Checks if the time component of the given DateTime falls within the specified time window (e.g. start <= dateTime < end).

public static bool IsWithinTimeWindow(this DateTime dateTime, TimeOnly startInclusive, TimeOnly endExclusive)

Parameters

dateTime DateTime
startInclusive TimeOnly
endExclusive TimeOnly

Returns

bool

Remarks

The time window can span across midnight. For example, a time window from 22:00 to 02:00 will include times from 22:00 to 23:59 and from 00:00 to 02:00.

NextWeekDay(DateTime)

Returns a new DateTime representing the next weekday (Monday to Friday) of the given DateTime.

public static DateTime NextWeekDay(this DateTime dateTime)

Parameters

dateTime DateTime

Returns

DateTime

PrevWeekDay(DateTime)

Returns a new DateTime representing the previous weekday (Monday to Friday) of the given DateTime.

public static DateTime PrevWeekDay(this DateTime dateTime)

Parameters

dateTime DateTime

Returns

DateTime

StartOfDay(DateTime)

Returns a new DateTime with the time component set to 00:00:00

public static DateTime StartOfDay(this DateTime dateTime)

Parameters

dateTime DateTime

Returns

DateTime