C# Класс EnterpriseWebLibrary.DateTimeTools

Provides helpful DateTime methods.
Показать файл Открыть проект

Открытые методы

Метод Описание
DateRangesCoverAllDates ( System.DateTime beginDate, System.DateTime endDate, DateTime?>.IEnumerable dateRanges ) : bool

Returns true when each day between begin and end dates is represented inside one of the date ranges in dateRanges, inclusive. Be sure time information is not included. No begin date may be after an end date.

DateRangesOverlap ( System.DateTime rangeOneBegin, System.DateTime rangeOneEnd, System.DateTime rangeTwoBegin, System.DateTime rangeTwoEnd ) : bool

Returns true if the two given date ranges overlap. Passing null for any date means infinity in that direction. Throws an exception if any of the given dates contains time information. Use .Date if you have to. See documentation for IsBetweenDates for more information on the date ranges.

DateTimeRangeOverlapsDateRange ( System.DateTime dateTimeRangeBegin, System.DateTime dateTimeRangeEnd, System.DateTime dateRangeBegin, System.DateTime dateRangeEnd ) : bool

Returns true if the specified date/time range overlaps the specified date range. Passing null for any date means infinity in that direction. Throws an exception if the date range contains time information. Use .Date if you have to. See documentation for IsBetweenDates for more information on the date range.

DateTimeRangesOverlap ( System.DateTime rangeOneBegin, System.DateTime rangeOneEnd, System.DateTime rangeTwoBegin, System.DateTime rangeTwoEnd ) : bool

Returns true if the two given DateTime ranges overlap. Passing null for any date/time means infinity in that direction.

GetDateOfDayOfWeekInMonth ( int year, int month, DayOfWeek day, int weeksFromFirst ) : System.DateTime

Gets the date of the specified day of the week in the specified month.

GetNumberOfFullYearsBetweenDates ( System.DateTime beginDate, System.DateTime endDate ) : int

This is useful for calculating someone's age. Beginning date must be before or equal to end date.

HasTime ( this dateTime ) : bool

Returns true if this date/time contains time information.

IsBetweenDateTimes ( this dateTime, System.DateTime onOrAfterDate, System.DateTime onOrBeforeDate ) : bool

Returns true if this date is in between the given DateTimes (inclusive at beginning of range, exclusive at end of range). Passing null for either of the two dates is considered to be infinity in that direction. Therefore, passing null for both dates will always result in true.

IsBetweenDates ( this dateTime, System.DateTime onOrAfterDate, System.DateTime onOrBeforeDate ) : bool

Returns true if this date is in between (inclusive) the given dates. This method differs from IsBetweenDateTimes in that onOrAfterDate and onOrBeforeDate must be dates only (an exception will be thrown if time information is passed - use .Date if you have to.) and that it is inclusive on both ends of the range. This method also correctly returns true in the case where the dateTime parameter is 3:30PM on 11/15/09 and the onOrBeforeDate is 11/15/09. If you want to define a range with time information, use IsBetweenDateTimes instead. Passing null for either of the two dates is considered to be infinity in that direction. Therefore, passing null for both dates will always result in true.

MonthBeginDate ( this date ) : System.DateTime

Returns the begin date of the specified date's month.

ToDayMonthYearString ( this dateTime, bool useLeadingZero, bool includeDayOfWeek = false ) : string

Formats the date portion of the specified date/time in "day month year" style, e.g. 5 Apr 2008.

ToDayMonthYearString ( this dateTime, string stringIfNull, bool useLeadingZero, bool includeDayOfWeek = false ) : string

Formats the date portion of the specified date/time in "day month year" style, e.g. 5 Apr 2008. Returns stringIfNull if the specified date/time is null.

ToHourAndMinuteString ( this dateTime ) : string

Formats the time portion of the specified date/time in hour:minute style followed by a single lowercase letter indicating AM or PM.

ToHourAndMinuteString ( this dateTime, string stringIfNull ) : string

Formats the time portion of the specified date/time in hour:minute style followed by a single lowercase letter indicating AM or PM. Returns stringIfNull if the specified date/time is null.

ToMonthDayYearString ( this dateTime ) : string

Formats the date portion of the specified date/time in "01/01/2001" style.

ToMonthDayYearString ( this dateTime, string stringIfNull ) : string

Formats the date portion of the specified date/time in "01/01/2001" style. Returns stringIfNull if the specified date/time is null.

ToMonthYearString ( this dateTime ) : string

Formats the date portion of the specified date/time in "month year" style, e.g. April 2008.

WeekBeginDate ( this dateTime ) : System.DateTime

Returns the date that the given week starts on.

WeeksFromFirstOccurrenceOfDayOfWeekInMonth ( this date, bool countBackwardFromFirstOccurrenceInNextMonth ) : int

Returns the number of weeks from the first occurrence of the specified date's day of the week in the month to the specified date.

Приватные методы

Метод Описание
assertDateTimeHasNoTime ( System.DateTime dateTime, string name ) : void

Описание методов

DateRangesCoverAllDates() публичный статический Метод

Returns true when each day between begin and end dates is represented inside one of the date ranges in dateRanges, inclusive. Be sure time information is not included. No begin date may be after an end date.
public static DateRangesCoverAllDates ( System.DateTime beginDate, System.DateTime endDate, DateTime?>.IEnumerable dateRanges ) : bool
beginDate System.DateTime
endDate System.DateTime
dateRanges DateTime?>.IEnumerable
Результат bool

DateRangesOverlap() публичный статический Метод

Returns true if the two given date ranges overlap. Passing null for any date means infinity in that direction. Throws an exception if any of the given dates contains time information. Use .Date if you have to. See documentation for IsBetweenDates for more information on the date ranges.
public static DateRangesOverlap ( System.DateTime rangeOneBegin, System.DateTime rangeOneEnd, System.DateTime rangeTwoBegin, System.DateTime rangeTwoEnd ) : bool
rangeOneBegin System.DateTime
rangeOneEnd System.DateTime
rangeTwoBegin System.DateTime
rangeTwoEnd System.DateTime
Результат bool

DateTimeRangeOverlapsDateRange() публичный статический Метод

Returns true if the specified date/time range overlaps the specified date range. Passing null for any date means infinity in that direction. Throws an exception if the date range contains time information. Use .Date if you have to. See documentation for IsBetweenDates for more information on the date range.
public static DateTimeRangeOverlapsDateRange ( System.DateTime dateTimeRangeBegin, System.DateTime dateTimeRangeEnd, System.DateTime dateRangeBegin, System.DateTime dateRangeEnd ) : bool
dateTimeRangeBegin System.DateTime
dateTimeRangeEnd System.DateTime
dateRangeBegin System.DateTime
dateRangeEnd System.DateTime
Результат bool

DateTimeRangesOverlap() публичный статический Метод

Returns true if the two given DateTime ranges overlap. Passing null for any date/time means infinity in that direction.
public static DateTimeRangesOverlap ( System.DateTime rangeOneBegin, System.DateTime rangeOneEnd, System.DateTime rangeTwoBegin, System.DateTime rangeTwoEnd ) : bool
rangeOneBegin System.DateTime
rangeOneEnd System.DateTime
rangeTwoBegin System.DateTime
rangeTwoEnd System.DateTime
Результат bool

GetDateOfDayOfWeekInMonth() публичный статический Метод

Gets the date of the specified day of the week in the specified month.
public static GetDateOfDayOfWeekInMonth ( int year, int month, DayOfWeek day, int weeksFromFirst ) : System.DateTime
year int The year.
month int The month.
day DayOfWeek The day of the week.
weeksFromFirst int The number of weeks from the first occurrence of the specified day of the week in the month. Pass a negative value to count /// backward from the first occurrence in the next month.
Результат System.DateTime

GetNumberOfFullYearsBetweenDates() публичный статический Метод

This is useful for calculating someone's age. Beginning date must be before or equal to end date.
public static GetNumberOfFullYearsBetweenDates ( System.DateTime beginDate, System.DateTime endDate ) : int
beginDate System.DateTime
endDate System.DateTime
Результат int

HasTime() публичный статический Метод

Returns true if this date/time contains time information.
public static HasTime ( this dateTime ) : bool
dateTime this
Результат bool

IsBetweenDateTimes() публичный статический Метод

Returns true if this date is in between the given DateTimes (inclusive at beginning of range, exclusive at end of range). Passing null for either of the two dates is considered to be infinity in that direction. Therefore, passing null for both dates will always result in true.
public static IsBetweenDateTimes ( this dateTime, System.DateTime onOrAfterDate, System.DateTime onOrBeforeDate ) : bool
dateTime this
onOrAfterDate System.DateTime
onOrBeforeDate System.DateTime
Результат bool

IsBetweenDates() публичный статический Метод

Returns true if this date is in between (inclusive) the given dates. This method differs from IsBetweenDateTimes in that onOrAfterDate and onOrBeforeDate must be dates only (an exception will be thrown if time information is passed - use .Date if you have to.) and that it is inclusive on both ends of the range. This method also correctly returns true in the case where the dateTime parameter is 3:30PM on 11/15/09 and the onOrBeforeDate is 11/15/09. If you want to define a range with time information, use IsBetweenDateTimes instead. Passing null for either of the two dates is considered to be infinity in that direction. Therefore, passing null for both dates will always result in true.
public static IsBetweenDates ( this dateTime, System.DateTime onOrAfterDate, System.DateTime onOrBeforeDate ) : bool
dateTime this
onOrAfterDate System.DateTime
onOrBeforeDate System.DateTime
Результат bool

MonthBeginDate() публичный статический Метод

Returns the begin date of the specified date's month.
public static MonthBeginDate ( this date ) : System.DateTime
date this
Результат System.DateTime

ToDayMonthYearString() публичный статический Метод

Formats the date portion of the specified date/time in "day month year" style, e.g. 5 Apr 2008.
public static ToDayMonthYearString ( this dateTime, bool useLeadingZero, bool includeDayOfWeek = false ) : string
dateTime this
useLeadingZero bool
includeDayOfWeek bool
Результат string

ToDayMonthYearString() публичный статический Метод

Formats the date portion of the specified date/time in "day month year" style, e.g. 5 Apr 2008. Returns stringIfNull if the specified date/time is null.
public static ToDayMonthYearString ( this dateTime, string stringIfNull, bool useLeadingZero, bool includeDayOfWeek = false ) : string
dateTime this
stringIfNull string
useLeadingZero bool
includeDayOfWeek bool
Результат string

ToHourAndMinuteString() публичный статический Метод

Formats the time portion of the specified date/time in hour:minute style followed by a single lowercase letter indicating AM or PM.
public static ToHourAndMinuteString ( this dateTime ) : string
dateTime this
Результат string

ToHourAndMinuteString() публичный статический Метод

Formats the time portion of the specified date/time in hour:minute style followed by a single lowercase letter indicating AM or PM. Returns stringIfNull if the specified date/time is null.
public static ToHourAndMinuteString ( this dateTime, string stringIfNull ) : string
dateTime this
stringIfNull string
Результат string

ToMonthDayYearString() публичный статический Метод

Formats the date portion of the specified date/time in "01/01/2001" style.
public static ToMonthDayYearString ( this dateTime ) : string
dateTime this
Результат string

ToMonthDayYearString() публичный статический Метод

Formats the date portion of the specified date/time in "01/01/2001" style. Returns stringIfNull if the specified date/time is null.
public static ToMonthDayYearString ( this dateTime, string stringIfNull ) : string
dateTime this
stringIfNull string
Результат string

ToMonthYearString() публичный статический Метод

Formats the date portion of the specified date/time in "month year" style, e.g. April 2008.
public static ToMonthYearString ( this dateTime ) : string
dateTime this
Результат string

WeekBeginDate() публичный статический Метод

Returns the date that the given week starts on.
public static WeekBeginDate ( this dateTime ) : System.DateTime
dateTime this
Результат System.DateTime

WeeksFromFirstOccurrenceOfDayOfWeekInMonth() публичный статический Метод

Returns the number of weeks from the first occurrence of the specified date's day of the week in the month to the specified date.
public static WeeksFromFirstOccurrenceOfDayOfWeekInMonth ( this date, bool countBackwardFromFirstOccurrenceInNextMonth ) : int
date this
countBackwardFromFirstOccurrenceInNextMonth bool
Результат int