Table of Contents

Class DateTimeOffsetExtensions

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

Extensions that provide utility methods for the DateTimeOffset struct.

public static class DateTimeOffsetExtensions
Inheritance
DateTimeOffsetExtensions
Inherited Members

Methods

AsTimeZoneSilently(DateTimeOffset, string)

Shifts the given DateTimeOffset to the specified time zone (e.g. keep date and time, change only the time zone). Returns null if the time zone ID is invalid or not found.

public static DateTimeOffset? AsTimeZoneSilently(this DateTimeOffset dateTime, string tzId)

Parameters

dateTime DateTimeOffset
tzId string

Returns

DateTimeOffset?

IsOnDayOfWeek(DateTimeOffset, IEnumerable<DayOfWeek>)

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

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

Parameters

dateTime DateTimeOffset
dows IEnumerable<DayOfWeek>

Returns

bool

IsOnDayOfWeek(DateTimeOffset, IEnumerable<string>)

Checks if the day of week component of the given DateTimeOffset 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 DateTimeOffset dateTime, IEnumerable<string> dows)

Parameters

dateTime DateTimeOffset
dows IEnumerable<string>

Returns

bool

IsOnDayOfWeek(DateTimeOffset, params DayOfWeek[])

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

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

Parameters

dateTime DateTimeOffset
dows DayOfWeek[]

Returns

bool

IsOnDayOfWeek(DateTimeOffset, params string[])

Checks if the day of week component of the given DateTimeOffset 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 DateTimeOffset dateTime, params string[] dows)

Parameters

dateTime DateTimeOffset
dows string[]

Returns

bool

IsWithinTimeWindow(DateTimeOffset, TimeOnly, TimeOnly)

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

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

Parameters

dateTime DateTimeOffset
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(DateTimeOffset)

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

public static DateTimeOffset NextWeekDay(this DateTimeOffset dateTime)

Parameters

dateTime DateTimeOffset

Returns

DateTimeOffset

PrevWeekDay(DateTimeOffset)

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

public static DateTimeOffset PrevWeekDay(this DateTimeOffset dateTime)

Parameters

dateTime DateTimeOffset

Returns

DateTimeOffset

StartOfDay(DateTimeOffset)

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

public static DateTimeOffset StartOfDay(this DateTimeOffset dateTime)

Parameters

dateTime DateTimeOffset

Returns

DateTimeOffset

ToTimeZoneSilently(DateTimeOffset, string)

Converts the given DateTimeOffset to the specified time zone. Returns null if the time zone ID is invalid or not found.

public static DateTimeOffset? ToTimeZoneSilently(this DateTimeOffset dateTime, string tzId)

Parameters

dateTime DateTimeOffset
tzId string

Returns

DateTimeOffset?