コード例 #1
0
 public DiaryDate(string baseDate, int months, int days, bool businessDays, bool bonding)
 {
     BaseDate       = new DiaryDateOption(baseDate);
     DaysToAdd      = days;
     MonthsToAdd    = months;
     IsBusinessDays = businessDays;
     IsBonding      = bonding;
 }
コード例 #2
0
        public DiaryDate(string date)
        {
            if (date.ToLower().Contains("str2date('14/'+copy(mplusstr((appdate)"))
            {
                IsBonding      = true;
                BaseDate       = new DiaryDateOption("appdate");
                IsBusinessDays = false;
                DaysToAdd      = 0;
                MonthsToAdd    = 1;
            }
            else
            {
                //remove any blank space
                string str = date.Trim(' ');
                //check for a working days calculation
                if (str.ToLower().Contains("addworkingdays"))
                {
                    IsBusinessDays = true;
                    int    startIndex = str.IndexOf('(') + 1;
                    int    endIndex   = str.IndexOf(',');
                    string temp       = str.Substring(startIndex, endIndex - startIndex);
                    DaysToAdd = int.Parse(temp);
                    str       = str.Substring(endIndex + 1, str.Length - endIndex - 1);
                }

                //non-working days will be at the end so handle that first
                //days cannot exceed 2 digits (otherwise it is a month
                //so look for a plus or a minus symbol
                int minusIndex = str.LastIndexOf("-");
                int plusIndex  = str.LastIndexOf("+");
                int length     = str.Length;
                //check minus first
                if (minusIndex != -1)
                {
                    //Then we have a day reduction
                    //capture everything from that point on
                    DaysToAdd = int.Parse(str.Substring(minusIndex));
                    //reduce the string length
                    str = str.Substring(0, minusIndex);
                }
                else if (plusIndex != -1)
                {
                    //Then we have a day addition
                    //capture everything from that point on
                    DaysToAdd = int.Parse(str.Substring(plusIndex));
                    //reduce the string length
                    str = str.Substring(0, plusIndex);
                }

                //now handle the months
                if (str.ToUpper().Contains("MPLUS("))
                {
                    //we have an adjustment the value will be 1 or 2 digits
                    //after a bracket
                    //reset length
                    length = str.Length;
                    //remove the trailing bracket
                    str = str.Substring(0, length - 1);
                    int months = 0;
                    if (int.TryParse(str.Substring(length - 3), out months))
                    {
                        //remove the digits and comma
                        str = str.Substring(0, length - 3);
                        str = str.Replace(',', ' ');
                        str = str.Trim();
                    }
                    else if (int.TryParse(str.Substring(length - 2), out months))
                    {
                        //remove the digit and comma
                        str = str.Substring(0, length - 2);
                        str = str.Replace(',', ' ');
                        str = str.Trim();
                    }
                    MonthsToAdd = months;
                    //reset length
                    length = str.Length;
                    //remove the mplus
                    str = str.Substring(5, length - 5);
                }
                //date becomes whatever is left, this will need to be check on return
                //just remove any remaining commas and brackets
                date     = str.Trim(',', '(', ')');
                BaseDate = new DiaryDateOption(date);
            }
        }