C# 클래스 EnterpriseWebLibrary.DateTimeTools

Provides helpful DateTime methods.
파일 보기 프로젝트 열기: enduracode/enterprise-web-library

공개 메소드들

메소드 설명
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