Exemple #1
0
        public static TimeItem IncDecTimeItem(INCDEC_OPERATOR incDec, TimeItem ti, float hoursToIncrementBy)
        {
            TimeItem tiIncremented;

            if (incDec == INCDEC_OPERATOR.INCREMENT)
            {
                tiIncremented = ti + hoursToIncrementBy;
            }
            else
            {
                tiIncremented = ti - hoursToIncrementBy;
            }
            return(tiIncremented);
        }
 public static string IncDec(string text, int stepsToIncrementBy, INCDEC_OPERATOR incDec, ref int selectionStart)
 {
     if (!String.IsNullOrWhiteSpace(text)) {
     var hoursToIncrementBy = stepsToIncrementBy * 15 / 60f;
     var parts = Enumerable.ToList(SplitIntoParts(text));
     int idx;
     //bool moveCursorLeft;
     int cursorInPartPosition;
     var part = FindPositionPart(parts, selectionStart, out idx, out cursorInPartPosition);
     var newPart = part;
     if (idx == 0 || (parts[0] == WorkDayParser.automaticPauseDeactivation && idx == 1)) {
       // is daystart, has no -
       TimeItem ti;
       if (TimeItem.TryParse(part, out ti)) {
     var tiIncremented = IncDecTimeItem(incDec, ti, hoursToIncrementBy);
     newPart = String.Format((string) "{0}", (object) tiIncremented.ToShortString());
       }
     } else if (part.StartsWith(WorkDayParser.endTimeStartChar.ToString())) {
       TimeItem ti;
       if (TimeItem.TryParse(part.TrimStart(WorkDayParser.endTimeStartChar), out ti)) {
     var tiIncremented = IncDecTimeItem(incDec, ti, hoursToIncrementBy);
     newPart = String.Format("{0}{1}", WorkDayParser.endTimeStartChar, tiIncremented.ToShortString());
       }
     } else {
       double t;
       if (Double.TryParse(part, NumberStyles.Any, CultureInfo.InvariantCulture, out t)) {
     double hIncremented;
     if (incDec == INCDEC_OPERATOR.INCREMENT) {
       hIncremented = t + hoursToIncrementBy;
     } else {
       hIncremented = t - hoursToIncrementBy;
     }
     newPart = hIncremented.ToString(CultureInfo.InvariantCulture);
       }
     }
     // check if we need to move cursor to left
     if (cursorInPartPosition > newPart.Length) {
       selectionStart = selectionStart - cursorInPartPosition + newPart.Length;
     }
     if (idx >= 0) {
       parts[idx] = newPart;
     }
     return parts.Aggregate(String.Empty, (aggr, s) => aggr + s);
       }
       return String.Empty;
 }
 public static TimeItem IncDecTimeItem(INCDEC_OPERATOR incDec, TimeItem ti, float hoursToIncrementBy)
 {
     TimeItem tiIncremented;
       if (incDec == INCDEC_OPERATOR.INCREMENT) {
     tiIncremented = ti + hoursToIncrementBy;
       } else {
     tiIncremented = ti - hoursToIncrementBy;
       }
       return tiIncremented;
 }
Exemple #4
0
 public static string IncDec(string text, int stepsToIncrementBy, INCDEC_OPERATOR incDec, ref int selectionStart)
 {
     if (!String.IsNullOrWhiteSpace(text))
     {
         var  hoursToIncrementBy = stepsToIncrementBy * 15 / 60f;
         var  parts = Enumerable.ToList(SplitIntoParts(text));
         int  idx;
         bool moveCursorLeft;
         int  cursorInPartPosition;
         var  part    = FindPositionPart(parts, selectionStart, out idx, out cursorInPartPosition);
         var  newPart = part;
         if (idx == 0 || (parts[0] == WorkDayParser.automaticPauseDeactivation && idx == 1))
         {
             // is daystart, has no -
             TimeItem ti;
             if (TimeItem.TryParse(part, out ti))
             {
                 var tiIncremented = IncDecTimeItem(incDec, ti, hoursToIncrementBy);
                 newPart = String.Format((string)"{0}", (object)tiIncremented.ToShortString());
             }
         }
         else if (part.StartsWith(WorkDayParser.endTimeStartChar.ToString()))
         {
             TimeItem ti;
             if (TimeItem.TryParse(part.TrimStart(WorkDayParser.endTimeStartChar), out ti))
             {
                 var tiIncremented = IncDecTimeItem(incDec, ti, hoursToIncrementBy);
                 newPart = String.Format("{0}{1}", WorkDayParser.endTimeStartChar, tiIncremented.ToShortString());
             }
         }
         else
         {
             double t;
             if (Double.TryParse(part, NumberStyles.Any, CultureInfo.InvariantCulture, out t))
             {
                 double hIncremented = t;
                 if (incDec == INCDEC_OPERATOR.INCREMENT)
                 {
                     hIncremented += hoursToIncrementBy;
                 }
                 else if ((hIncremented - hoursToIncrementBy) >= 0)
                 {
                     // do not go below zero
                     hIncremented -= hoursToIncrementBy;
                 }
                 newPart = hIncremented.ToString(CultureInfo.InvariantCulture);
             }
         }
         // check if we need to move cursor to left
         if (cursorInPartPosition > newPart.Length)
         {
             selectionStart = selectionStart - cursorInPartPosition + newPart.Length;
         }
         if (idx >= 0)
         {
             parts[idx] = newPart;
         }
         return(parts.Aggregate(String.Empty, (aggr, s) => aggr + s));
     }
     return(String.Empty);
 }