Show / Hide Table of Contents

Class DateTimeExtensions

This class implements two overloads of DateOfMostRecentWeekdayDay, a static method, implemented as an extension method on the System.DateTime type. The two overloads accept their one externally visible argment as either a DayOfWeek enumeration member or its integral value.

Inheritance
System.Object
DateTimeExtensions
Namespace: WizardWrx
Assembly: WizardWrx.Core.dll
Syntax
public static class DateTimeExtensions : object

Methods

| Improve this Doc View Source

DateOfMostRecentWeekday(DateTime, DayOfWeek)

Given a date and a day of the week, return the date of the most recent instance of the specified day of the week.

Declaration
public static DateTime DateOfMostRecentWeekday(this DateTime pdtmThisDate, DayOfWeek penmDayOfWeek)
Parameters
Type Name Description
DateTime pdtmThisDate

Specify the DateTime to serve as the reference point against which calculate the most recent weekday given by penmDayOfWeek.

DayOfWeek penmDayOfWeek

Specify the weekday in terms of the DayOfWeek enumeration for which the weekday nearest to pdtmThisDate is desired.

Returns
Type Description
DateTime

The return value is the date, represented as a DateTime object, for which the DayOfWeek property is the value specified by penmDayOfWeek that is the most recent instance of the specified weekday that is on or before the date specified by pdtmThisDate.

Remarks

Since enumerated types can be freely converted to and from integers, and a program stands a fair chance of having the weekday specified in terms of either, two versions of this method are offered. Since integers are easier to manipulate, the overload that accepts the integer representation of the weekday implements both; the overload that takes the enumeration casts it to integer and calls the other overload, through which it returns.

Examples

When pdtmThisDate is 03/08/2022 and penmDayOfWeek is Sunday, the return value is Sunday, 03/06/2022.

| Improve this Doc View Source

DateOfMostRecentWeekday(DateTime, Int32)

Given a date and a day of the week, return the date of the most recent instance of the specified day of the week.

Declaration
public static DateTime DateOfMostRecentWeekday(this DateTime pdtmThisDate, int pintDayOfWeekIndex)
Parameters
Type Name Description
DateTime pdtmThisDate

Specify the DateTime to serve as the reference point against which calculate the most recent weekday given by pintDayOfWeekIndex.

System.Int32 pintDayOfWeekIndex

Specify the weekday in terms of the integer that maps to the intended DayOfWeek enumeration value for which the weekday nearest to pdtmThisDate is desired.

Returns
Type Description
DateTime

The return value is the date, represented as a DateTime object, for which the DayOfWeek property is the value specified as integer pintDayOfWeekIndex that is the most recent instance of the specified weekday that is on or before the date specified by pdtmThisDate.

Remarks

Since enumerated types can be freely converted to and from integers, and a program stands a fair chance of having the weekday specified in terms of either, two versions of this method are offered. Since integers are easier to manipulate, the overload that accepts the integer representation of the weekday implements both; the overload that takes the enumeration casts it to integer and calls the other overload, through which it returns.

Examples

When pdtmThisDate is 03/08/2022 and pintDayOfWeekIndex is Sunday, the return value is Sunday, 03/06/2022.

  • Improve this Doc
  • View Source
Back to top Generated by DocFX