C# Class Habanero.Util.DateTimeUtilities

General utilities used for datetime manipulation e.g. LastDayOfMonth
Show file Open project: Chillisoft/habanero

Public Methods

Method Description
CloseToDateTimeNow ( System.DateTime valueToCheck, int toleranceInSeconds ) : bool

Indicates whether the given DateTime value is close to DateTime.Now, within the given tolerance range

DayEnd ( System.DateTime date ) : System.DateTime

Converts the given date to the previous midnight, factoring in the midnight offset

DayEnd ( System.DateTime date, System.TimeSpan dayStartOffSet ) : System.DateTime

Converts the given date to the previous midnight, factoring in the midnight offset

DayStart ( System.DateTime date ) : System.DateTime

Converts the given date to the previous midnight, factoring in the midnight offset

DayStart ( System.DateTime date, System.TimeSpan dayStartOffSet ) : System.DateTime

Converts the given date to the previous midnight, factoring in the midnight offset

FirstDayOFinancialYear ( int monthFinancialYearStarts ) : System.DateTime

Returns the first day of the current financial year. If the financial year starts in march then monthFinancialYearStarts = 3. If the current date is before 01 March e.g. 12 Feb 2007 then the the current financial year starts on the 01 March 2006. Then the current date is after 01 March e.g. 21 August 2007 then the current financial year starts on the 01 March 2007.

FirstDayOFinancialYear ( int monthFinancialYearStarts, System.DateTime currentDate ) : System.DateTime

Returns the first day of the current financial year. If the financial year starts in march then monthFinancialYearStarts = 3. If the current date is before 01 March e.g. 12 Feb 2007 then the the current financial year starts on the 01 March 2006. Then the current date is after 01 March e.g. 21 August 2007 then the current financial year starts on the 01 March 2007.

FirstDayOfMonth ( ) : System.DateTime

returns the first day of the current month

FirstDayOfMonth ( System.DateTime dte ) : System.DateTime

returns the first day of the month specified by dte

HourEnd ( System.DateTime date ) : System.DateTime

Converts the given date to the start of the hour

HourStart ( System.DateTime date ) : System.DateTime

Converts the given date to the start of the hour

IsWeekDay ( System.DateTime date ) : bool

Determines whether is week day.

LastDayOfFinancialYear ( int monthFinancialYearStarts, System.DateTime currentDate ) : System.DateTime

Returns the last day of the current financial year (the current financial year is determined by the current date). If the financial year starts in march then monthFinancialYearStarts = 3. If the current date is before 01 March e.g. 12 Feb 2007 then the the current financial year starts on the 01 March 2006 and ends on the 28 Feb 2007. If the current date is after 01 March e.g. 21 August 2007 then the current financial year starts on the 01 March 2007 and ends on the 29 Feb 2008.

LastDayOfTheMonth ( ) : System.DateTime

returns the last day of the current month (i.e. LastDayOfTheMonth(Today)

LastDayOfTheMonth ( System.DateTime dte ) : System.DateTime

returns the last day of the month defined by dte

MonthEnd ( System.DateTime currentDateTime ) : System.DateTime

The MonthEnd For the currentDateTime where the MonthEnd is assumed to be Saturday

MonthEnd ( System.DateTime currentDateTime, System.TimeSpan startOfMonthOffSet ) : System.DateTime

The MonthEnd For the currentDateTime

MonthStart ( System.DateTime currentDateTime ) : System.DateTime

The FirstDay of the currentDateTime

MonthStart ( System.DateTime currentDateTime, System.TimeSpan monthStartOffSet ) : System.DateTime

The FirstDay of the currentDateTime taking into a

NextBusinessDay ( System.DateTime date ) : System.DateTime

Next Business Day (not Sat or Sun) Does not take into account public holidays.

OnOrNextBusinessDay ( System.DateTime date ) : System.DateTime

Returns unchanged if is business day else subsequent Monday. Does not take into account public holidays.

OnOrNextDayOfWeek ( System.DateTime date, DayOfWeek day ) : System.DateTime

Return the date if it is on the day of the week. Else returns the following day. This i used to iteratively walk through days untill you find the ' day the next day that is the day of the week.

OnOrPreviousBusinessDay ( System.DateTime date ) : System.DateTime

Returns unchanged if is business day else previous Friday Does not take into account public holidays.

OnOrPreviousDayOfWeek ( System.DateTime date, DayOfWeek day ) : System.DateTime

Return the date if it is on the day of the week. Else returns the previous day. This i used to iteratively walk through days untill you find the previous day that is the day of the week.

ParseToDate ( object valueToParse ) : System.DateTime

Parses the valueToParse to a valid date time

PreviousBusinessDay ( System.DateTime date ) : System.DateTime

Previous Trade Day (not Sat or Sun) Does not take into account public holidays.

TryParseDate ( object valueToParse, System.DateTime &returnValue ) : bool

Tries to parse a value as an object to a valid DateTime. The valid value may not be a date will always be a date i.e. "Now" will resolve to now. If you need lazy resolution then use TryParseValue.

TryParseValue ( object valueToParse, object &returnValue ) : bool

Tries to parse a value as an object to a valid DateTimeValue or a resolvable DateTimeValue. The valid value may not be a date but could instead return a DateTimeToday or DateTimeNow etc These objects are convertable to DateTime via the DateTimeToday.ResolveToValue

WeekEnd ( System.DateTime currentDateTime ) : System.DateTime

The WeekEnd For the currentDateTime where the WeekEnd is assumed to be Saturday

WeekEnd ( System.DateTime currentDateTime, System.TimeSpan startOfWeekOffSet ) : System.DateTime

The WeekEnd For the currentDateTime

WeekStart ( System.DateTime currentDateTime ) : System.DateTime

The WeekStart for the currentDateTime where the WeekStart is assumed to be Sunday

WeekStart ( System.DateTime currentDateTime, System.TimeSpan weekStartOffSet ) : System.DateTime

Converts the given date to the previous Monday midnight, factoring in the midnight offset and week start

YearEnd ( System.DateTime currentDateTime ) : System.DateTime

The YearEnd For the currentDateTime

YearEnd ( System.DateTime currentDateTime, int noOfMonthsOffSet ) : System.DateTime

The YearEnd For the currentDateTime

YearEnd ( System.DateTime currentDateTime, int noOfMonthsOffSet, System.TimeSpan monthStartOffSet ) : System.DateTime

The YearEnd For the currentDateTime

YearStart ( System.DateTime currentDateTime ) : System.DateTime

The Very first second of this year.

YearStart ( System.DateTime currentDateTime, int noOfMonthsOffSet ) : System.DateTime

The very first second of this year plus the offset. This is typically used for Financial Year type calculations e.g. when you are looking for a year starting on 01 March use a noOfMonthsOffSet = 2.

YearStart ( System.DateTime currentDateTime, int noOfMonthsOffSet, System.TimeSpan monthStartOffSet ) : System.DateTime

The very first second of this year plus the month offset plus the Time offset. This is typically used for Financial Year type calculations e.g. when you are looking for a year starting on 01 March use a noOfMonthsOffSet = 2.

Private Methods

Method Description
ParseValue ( object valueToParse ) : object
RaiseIncorrectTypeException ( object value ) : void

Raises an Erorr if the Incorrect type of property is being set to this BOProp.

Method Details

CloseToDateTimeNow() public static method

Indicates whether the given DateTime value is close to DateTime.Now, within the given tolerance range
public static CloseToDateTimeNow ( System.DateTime valueToCheck, int toleranceInSeconds ) : bool
valueToCheck System.DateTime The DateTime value to check
toleranceInSeconds int The maximum number of distance in seconds that /// the value can be from Now and still be accepted
return bool

DayEnd() public static method

Converts the given date to the previous midnight, factoring in the midnight offset
public static DayEnd ( System.DateTime date ) : System.DateTime
date System.DateTime The date to convert
return System.DateTime

DayEnd() public static method

Converts the given date to the previous midnight, factoring in the midnight offset
public static DayEnd ( System.DateTime date, System.TimeSpan dayStartOffSet ) : System.DateTime
date System.DateTime The date to convert
dayStartOffSet System.TimeSpan You can offset the Date Start (typically used when you wan to report on date starting at 8:00 am)
return System.DateTime

DayStart() public static method

Converts the given date to the previous midnight, factoring in the midnight offset
public static DayStart ( System.DateTime date ) : System.DateTime
date System.DateTime The date to convert
return System.DateTime

DayStart() public static method

Converts the given date to the previous midnight, factoring in the midnight offset
public static DayStart ( System.DateTime date, System.TimeSpan dayStartOffSet ) : System.DateTime
date System.DateTime The date to convert
dayStartOffSet System.TimeSpan You can offset the Date Start (typically used when you wan to report on date starting at 8:00 am)
return System.DateTime

FirstDayOFinancialYear() public static method

Returns the first day of the current financial year. If the financial year starts in march then monthFinancialYearStarts = 3. If the current date is before 01 March e.g. 12 Feb 2007 then the the current financial year starts on the 01 March 2006. Then the current date is after 01 March e.g. 21 August 2007 then the current financial year starts on the 01 March 2007.
public static FirstDayOFinancialYear ( int monthFinancialYearStarts ) : System.DateTime
monthFinancialYearStarts int the month that the financial year starts usually march in south africa
return System.DateTime

FirstDayOFinancialYear() public static method

Returns the first day of the current financial year. If the financial year starts in march then monthFinancialYearStarts = 3. If the current date is before 01 March e.g. 12 Feb 2007 then the the current financial year starts on the 01 March 2006. Then the current date is after 01 March e.g. 21 August 2007 then the current financial year starts on the 01 March 2007.
public static FirstDayOFinancialYear ( int monthFinancialYearStarts, System.DateTime currentDate ) : System.DateTime
monthFinancialYearStarts int the month that the financial year starts usually march in south africa
currentDate System.DateTime The date for which you wish to calculate the first day of the financial year
return System.DateTime

FirstDayOfMonth() public static method

returns the first day of the current month
public static FirstDayOfMonth ( ) : System.DateTime
return System.DateTime

FirstDayOfMonth() public static method

returns the first day of the month specified by dte
public static FirstDayOfMonth ( System.DateTime dte ) : System.DateTime
dte System.DateTime
return System.DateTime

HourEnd() public static method

Converts the given date to the start of the hour
public static HourEnd ( System.DateTime date ) : System.DateTime
date System.DateTime The date to convert
return System.DateTime

HourStart() public static method

Converts the given date to the start of the hour
public static HourStart ( System.DateTime date ) : System.DateTime
date System.DateTime The date to convert
return System.DateTime

IsWeekDay() public static method

Determines whether is week day.
public static IsWeekDay ( System.DateTime date ) : bool
date System.DateTime The date.
return bool

LastDayOfFinancialYear() public static method

Returns the last day of the current financial year (the current financial year is determined by the current date). If the financial year starts in march then monthFinancialYearStarts = 3. If the current date is before 01 March e.g. 12 Feb 2007 then the the current financial year starts on the 01 March 2006 and ends on the 28 Feb 2007. If the current date is after 01 March e.g. 21 August 2007 then the current financial year starts on the 01 March 2007 and ends on the 29 Feb 2008.
public static LastDayOfFinancialYear ( int monthFinancialYearStarts, System.DateTime currentDate ) : System.DateTime
monthFinancialYearStarts int the month that the financial year starts usually march in south africa
currentDate System.DateTime The date for which you wish to calculate the last day of the financial year
return System.DateTime

LastDayOfTheMonth() public static method

returns the last day of the current month (i.e. LastDayOfTheMonth(Today)
public static LastDayOfTheMonth ( ) : System.DateTime
return System.DateTime

LastDayOfTheMonth() public static method

returns the last day of the month defined by dte
public static LastDayOfTheMonth ( System.DateTime dte ) : System.DateTime
dte System.DateTime
return System.DateTime

MonthEnd() public static method

The MonthEnd For the currentDateTime where the MonthEnd is assumed to be Saturday
public static MonthEnd ( System.DateTime currentDateTime ) : System.DateTime
currentDateTime System.DateTime
return System.DateTime

MonthEnd() public static method

The MonthEnd For the currentDateTime
public static MonthEnd ( System.DateTime currentDateTime, System.TimeSpan startOfMonthOffSet ) : System.DateTime
currentDateTime System.DateTime
startOfMonthOffSet System.TimeSpan The OffSet
return System.DateTime

MonthStart() public static method

The FirstDay of the currentDateTime
public static MonthStart ( System.DateTime currentDateTime ) : System.DateTime
currentDateTime System.DateTime
return System.DateTime

MonthStart() public static method

The FirstDay of the currentDateTime taking into a
public static MonthStart ( System.DateTime currentDateTime, System.TimeSpan monthStartOffSet ) : System.DateTime
currentDateTime System.DateTime
monthStartOffSet System.TimeSpan
return System.DateTime

NextBusinessDay() public static method

Next Business Day (not Sat or Sun) Does not take into account public holidays.
public static NextBusinessDay ( System.DateTime date ) : System.DateTime
date System.DateTime The date.
return System.DateTime

OnOrNextBusinessDay() public static method

Returns unchanged if is business day else subsequent Monday. Does not take into account public holidays.
public static OnOrNextBusinessDay ( System.DateTime date ) : System.DateTime
date System.DateTime The date.
return System.DateTime

OnOrNextDayOfWeek() public static method

Return the date if it is on the day of the week. Else returns the following day. This i used to iteratively walk through days untill you find the ' day the next day that is the day of the week.
public static OnOrNextDayOfWeek ( System.DateTime date, DayOfWeek day ) : System.DateTime
date System.DateTime
day DayOfWeek
return System.DateTime

OnOrPreviousBusinessDay() public static method

Returns unchanged if is business day else previous Friday Does not take into account public holidays.
public static OnOrPreviousBusinessDay ( System.DateTime date ) : System.DateTime
date System.DateTime The date.
return System.DateTime

OnOrPreviousDayOfWeek() public static method

Return the date if it is on the day of the week. Else returns the previous day. This i used to iteratively walk through days untill you find the previous day that is the day of the week.
public static OnOrPreviousDayOfWeek ( System.DateTime date, DayOfWeek day ) : System.DateTime
date System.DateTime
day DayOfWeek
return System.DateTime

ParseToDate() public static method

Parses the valueToParse to a valid date time
Exception raised if value cannot be parsed
public static ParseToDate ( object valueToParse ) : System.DateTime
valueToParse object
return System.DateTime

PreviousBusinessDay() public static method

Previous Trade Day (not Sat or Sun) Does not take into account public holidays.
public static PreviousBusinessDay ( System.DateTime date ) : System.DateTime
date System.DateTime The date.
return System.DateTime

TryParseDate() public static method

Tries to parse a value as an object to a valid DateTime. The valid value may not be a date will always be a date i.e. "Now" will resolve to now. If you need lazy resolution then use TryParseValue.
public static TryParseDate ( object valueToParse, System.DateTime &returnValue ) : bool
valueToParse object
returnValue System.DateTime valid date if try Parse true else null
return bool

TryParseValue() public static method

Tries to parse a value as an object to a valid DateTimeValue or a resolvable DateTimeValue. The valid value may not be a date but could instead return a DateTimeToday or DateTimeNow etc These objects are convertable to DateTime via the DateTimeToday.ResolveToValue
public static TryParseValue ( object valueToParse, object &returnValue ) : bool
valueToParse object
returnValue object
return bool

WeekEnd() public static method

The WeekEnd For the currentDateTime where the WeekEnd is assumed to be Saturday
public static WeekEnd ( System.DateTime currentDateTime ) : System.DateTime
currentDateTime System.DateTime
return System.DateTime

WeekEnd() public static method

The WeekEnd For the currentDateTime
public static WeekEnd ( System.DateTime currentDateTime, System.TimeSpan startOfWeekOffSet ) : System.DateTime
currentDateTime System.DateTime
startOfWeekOffSet System.TimeSpan The OffSet
return System.DateTime

WeekStart() public static method

The WeekStart for the currentDateTime where the WeekStart is assumed to be Sunday
public static WeekStart ( System.DateTime currentDateTime ) : System.DateTime
currentDateTime System.DateTime
return System.DateTime

WeekStart() public static method

Converts the given date to the previous Monday midnight, factoring in the midnight offset and week start
public static WeekStart ( System.DateTime currentDateTime, System.TimeSpan weekStartOffSet ) : System.DateTime
currentDateTime System.DateTime The date to convert
weekStartOffSet System.TimeSpan The off set period
return System.DateTime

YearEnd() public static method

The YearEnd For the currentDateTime
public static YearEnd ( System.DateTime currentDateTime ) : System.DateTime
currentDateTime System.DateTime
return System.DateTime

YearEnd() public static method

The YearEnd For the currentDateTime
public static YearEnd ( System.DateTime currentDateTime, int noOfMonthsOffSet ) : System.DateTime
currentDateTime System.DateTime
noOfMonthsOffSet int The OffSet
return System.DateTime

YearEnd() public static method

The YearEnd For the currentDateTime
public static YearEnd ( System.DateTime currentDateTime, int noOfMonthsOffSet, System.TimeSpan monthStartOffSet ) : System.DateTime
currentDateTime System.DateTime
noOfMonthsOffSet int The number of moths that are OffSet i.e. offset = 3 will result in year start 1 Apr and Year End 31 Mar
monthStartOffSet System.TimeSpan
return System.DateTime

YearStart() public static method

The Very first second of this year.
public static YearStart ( System.DateTime currentDateTime ) : System.DateTime
currentDateTime System.DateTime
return System.DateTime

YearStart() public static method

The very first second of this year plus the offset. This is typically used for Financial Year type calculations e.g. when you are looking for a year starting on 01 March use a noOfMonthsOffSet = 2.
public static YearStart ( System.DateTime currentDateTime, int noOfMonthsOffSet ) : System.DateTime
currentDateTime System.DateTime the currentDate from which the YearStart should be calculated
noOfMonthsOffSet int The noOfMonthsOffSet used to
return System.DateTime

YearStart() public static method

The very first second of this year plus the month offset plus the Time offset. This is typically used for Financial Year type calculations e.g. when you are looking for a year starting on 01 March use a noOfMonthsOffSet = 2.
public static YearStart ( System.DateTime currentDateTime, int noOfMonthsOffSet, System.TimeSpan monthStartOffSet ) : System.DateTime
currentDateTime System.DateTime the currentDate from which the YearStart should be calculated
noOfMonthsOffSet int The noOfMonthsOffSet used to
monthStartOffSet System.TimeSpan
return System.DateTime