Esempio n. 1
0
        public DateTime GetEndDate(DateTime StartDate, double estimatedEfforts, string acrStatus, int numberOfAssignees)
        {
            if (acrStatus == "ACR Scheduled")
               {
               int totalDays = Convert.ToInt32(Math.Ceiling(estimatedEfforts / numberOfAssignees));
               DateTime endDate = StartDate.AddBusinessDays(totalDays);
               return endDate;
               }

               else
               {
               throw new InvalidOperationException("ACR Not Scheduled");
               }
        }
Esempio n. 2
0
        /// <summary>
        /// Private function adds or subtracts the given period.
        /// </summary>
        /// <param name="date"></param>
        /// <param name="period">A <see cref="Period"/>.</param>
        /// <param name="convention">See <see cref="Convention">.</param>
        /// <param name="calendar">The holiday calendar.</param>
        /// <param name="negate">Subtracts the period if True, otherwise adds it.</param>
        private static DateTime AddPeriod(this DateTime date, Period period, Convention convention, SortedSet <DateTime> calendar, bool negate)
        {
            DateTime newDate = date.TruncateTime();
            int      mult    = (negate) ? -1 : 1;

            switch (period.Type)
            {
            case PeriodType.Year:
                newDate = newDate.AddYears(mult * period.NumPeriods);
                break;

            case PeriodType.Month:
                newDate = newDate.AddMonths(mult * period.NumPeriods);
                break;

            case PeriodType.Week:
                newDate = newDate.AddWeeks(mult * period.NumPeriods);
                break;

            case PeriodType.BusinessDay:
                newDate = newDate.AddBusinessDays(mult * period.NumPeriods, calendar);
                break;

            case PeriodType.Day:
                newDate = newDate.AddDays(mult * period.NumPeriods);
                break;

            case PeriodType.IMM:
                if (mult * period.NumPeriods < 0)
                {
                    throw new ArgumentException("Cannot subtract IMM periods from a date");
                }

                for (int i = 0; i < mult * period.NumPeriods; i++)
                {
                    newDate = newDate.NextIMM();
                }
                break;
            }

            newDate = newDate.Modify(convention, calendar);

            return(newDate);
        }
Esempio n. 3
0
        private static DateTime GetHourWithinBusinessDay(DateTime dateTime, int startOfDayHour, int endOfDayHour, int startOfDayMinute, int endOfDayMinute)
        {
            var startOfDay = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, startOfDayHour, startOfDayMinute, 0);
            var endOfDay = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, endOfDayHour, endOfDayMinute, 0);

            if (dateTime < startOfDay)
                return startOfDay;

            return dateTime > endOfDay
                       ? startOfDay.AddBusinessDays(1)
                       : dateTime;
        }
Esempio n. 4
0
        /// <summary>
        /// Private function adds or subtracts the given period expressed as a string.
        /// </summary>
        /// <param name="date"></param>
        /// <param name="periodString">A case insensitive string representing a period as a set of concatenated elements each conforming to a [number][period type] pattern.
        /// The period type can be "y" for years, "m" of months, "w" for weeks, "d" for days, "b" for business days and either "i" or"f" for IMM futures periods.
        /// Examples are "1y3m2d", "5w3d", "8bd".</param>
        /// <param name="convention">See <see cref="Convention">.</param>
        /// <param name="calendar">The holiday calendar.</param>
        /// <param name="negate">Subtracts the period if True, otherwise adds it.</param>
        private static DateTime AddPeriod(this DateTime date, string periodString, Convention convention, SortedSet <DateTime> calendar, bool negate)
        {
            DateTime newDate = date.TruncateTime();;

            string[] split          = periodString.Split(new Char[] { 'Y', 'M', 'W', 'D', 'B', 'I', 'F' });
            int      location       = -1;
            string   previousString = "";
            bool     previousBlank  = false;

            foreach (string s in split)
            {
                if (s.Length == 0)
                {
                    previousBlank = true;
                    continue;
                }

                if (previousBlank || !int.TryParse(s, out int period))
                {
                    throw new ArgumentException("Invalid period string: '" + periodString + "'");
                }

                if (negate)
                {
                    period = -period;
                }

                location += s.Length + 1;

                switch (periodString.Substring(location, 1))
                {
                case "Y":
                    if (previousString != "")
                    {
                        throw new ArgumentException("Invalid period string: '" + periodString + "'");
                    }
                    newDate        = newDate.AddYears(period);
                    previousString = "Y";
                    break;

                case "M":
                    if (previousString != "" &&
                        previousString != "Y")
                    {
                        throw new ArgumentException("Invalid period string: '" + periodString + "'");
                    }
                    newDate        = newDate.AddMonths(period);
                    previousString = "M";
                    break;

                case "W":
                    if (previousString != "" &&
                        previousString != "Y" &&
                        previousString != "M")
                    {
                        throw new ArgumentException("Invalid period string: '" + periodString + "'");
                    }
                    newDate        = newDate.AddWeeks(period);
                    previousString = "W";
                    break;

                case "D":
                    if (previousString != "" &&
                        previousString != "Y" &&
                        previousString != "M" &&
                        previousString != "W")
                    {
                        throw new ArgumentException("Invalid period string: '" + periodString + "'");
                    }
                    newDate        = newDate.AddDays(period);
                    previousString = "D";
                    break;

                case "B":
                    if (previousString != "")
                    {
                        throw new ArgumentException("Invalid period string: '" + periodString + "'");
                    }
                    newDate        = newDate.AddBusinessDays(period, calendar);
                    previousString = "B";
                    break;

                case "F":
                case "I":
                    if (previousString != "")
                    {
                        throw new ArgumentException("Invalid period string: '" + periodString + "'");
                    }
                    for (int i = 0; i < period; i++)
                    {
                        newDate = newDate.NextIMM();
                    }
                    previousString = "I";
                    break;
                }
            }

            newDate = newDate.Modify(convention, calendar);

            return(newDate);
        }