Beispiel #1
0
        /// <summary>
        /// Calulates Business Days within the given range of days.
        /// Start date and End date inclusive.
        /// </summary>
        /// <param name="StartDate">Datetime object
        /// containing Starting Date</param>
        /// <param name="EndDate">Datetime object containing
        /// End Date</param>
        /// <param name="BusinessDaysPerWeek">integer denoting No of Business
        /// Day in a week</param>
        /// <returns></returns>
        public static double CountBusinessDays(DateTime StartDate, DateTime EndDate, int BusinessDaysPerWeek)
        {
            double iWeek, iDays, isDays, ieDays;

            //* Find the number of weeks between the dates. Subtract 1 */
            // since we do not want to count the current week. * /
            iWeek = DateTools.DateDiff("ww", StartDate, EndDate) - 1;
            iDays = iWeek * BusinessDaysPerWeek;
            //
            if (BusinessDaysPerWeek == 5)
            {
                //-- If Saturday, Sunday is holiday
                if (StartDate.DayOfWeek == DayOfWeek.Saturday)
                {
                    isDays = 7 - (int)StartDate.DayOfWeek;
                }
                else
                {
                    isDays = 7 - (int)StartDate.DayOfWeek - 1;
                }
            }
            else
            {
                //-- If Sunday is only <st1:place>Holiday</st1:place>
                isDays = 7 - (int)StartDate.DayOfWeek;
            }
            //-- Calculate the days in the last week. These are not included in the
            //-- week calculation. Since we are starting with the end date, we only
            //-- remove the Sunday (datepart=1) from the number of days. If the end
            //-- date is Saturday, correct for this.
            if (BusinessDaysPerWeek == 5)
            {
                if (EndDate.DayOfWeek == DayOfWeek.Saturday)
                {
                    ieDays = (int)EndDate.DayOfWeek - 2;
                }
                else
                {
                    ieDays = (int)EndDate.DayOfWeek - 1;
                }
            }
            else
            {
                ieDays = (int)EndDate.DayOfWeek - 1;
            }
            //-- Sum everything together.
            iDays = iDays + isDays + ieDays;

            return(iDays);
        }
Beispiel #2
0
 /// <summary>
 /// Returs true if the given date is Columbus Day
 /// </summary>
 public static bool IsColumbusDay(DateTime p_date)
 {
     //Second Monday in Oct
     return(p_date.Month == 10 && (p_date.Day == DateTools.NthDayOfWeekOfMonth(2, DayOfWeek.Monday, p_date)));
 }
Beispiel #3
0
 /// <summary>
 /// Returs true if the given date is Presidents Day
 /// </summary>
 public static bool IsPresidentsDay(DateTime p_date)
 {
     //Third Monday in Feb
     return(p_date.Month == 2 && (p_date.Day == DateTools.NthDayOfWeekOfMonth(3, DayOfWeek.Monday, p_date)));
 }
Beispiel #4
0
 /// <summary>
 /// Returs true if the given date is Labor Day
 /// </summary>
 public static bool IsLaborDay(DateTime p_date)
 {
     //First Monday in Sept.
     return(p_date.Month == 9 && (p_date.Day == DateTools.NthDayOfWeekOfMonth(1, DayOfWeek.Monday, p_date)));
 }
Beispiel #5
0
 /// <summary>
 /// Returs true if the given date is Martin Luther King Day
 /// </summary>
 public static bool IsMartinLutherKingDay(DateTime p_date)
 {
     //Third monday in january
     return(p_date.Month == 1 && (p_date.Day == DateTools.NthDayOfWeekOfMonth(3, DayOfWeek.Monday, p_date)));
 }