예제 #1
0
        DateTime getTime()
        {
            DateTime gc;

            // absoulte time, this is easy
            if (type == TYPE_ABSOLUTE)
            {
                gc = new DateTime(year + 1900, month, day, hour, min, sec);
            }
            // relative time, we need a context to evaluate it
            else if (context != null && context.type == TYPE_ABSOLUTE)
            {
                gc = context.getTime();
            }
            // how would I guess what time it was?
            else
            {
                throw new ApplicationException("Relative times like '" + dateString +
                                               "' require proper absolute context to be evaluated");
            }
            gc = gc.AddYears(dyear);
            gc = gc.AddMonths(dmonth);
            gc = gc.AddDays(dday);
            gc = gc.AddHours(dhour);
            gc = gc.AddMinutes(dmin);
            gc = gc.AddSeconds(dsec);
            return(gc);
        }
예제 #2
0
 /**
  * Use this static method to resolve relative time references and obtain the corresponding
  * Calendar objects. Example:<p>
  * <pre>
  * TimeParser pStart = new TimeParser("now-1month"); // starting time
  * TimeParser pEnd = new TimeParser("start+1week");  // ending time
  * TimeSpec specStart = pStart.parse();
  * TimeSpec specEnd = pEnd.parse();
  * GregorianCalendar[] gc = TimeSpec.getTimes(specStart, specEnd);
  * </pre>
  * @param spec1 Starting time specification
  * @param spec2 Ending time specification
  * @return Two element array containing Calendar objects
  */
 public static DateTime[] getTimes(TimeSpec spec1, TimeSpec spec2)
 {
     if (spec1.type == TYPE_START || spec2.type == TYPE_END)
     {
         throw new ArgumentException("Recursive time specifications not allowed");
     }
     spec1.context = spec2;
     spec2.context = spec1;
     return(new[] {
         spec1.getTime(),
         spec2.getTime()
     });
 }
예제 #3
0
파일: TimeSpec.cs 프로젝트: mujing/rrd4net
 /**
  * Use this static method to resolve relative time references and obtain the corresponding
  * Calendar objects. Example:<p>
  * <pre>
  * TimeParser pStart = new TimeParser("now-1month"); // starting time
  * TimeParser pEnd = new TimeParser("start+1week");  // ending time
  * TimeSpec specStart = pStart.parse();
  * TimeSpec specEnd = pEnd.parse();
  * GregorianCalendar[] gc = TimeSpec.getTimes(specStart, specEnd);
  * </pre>
  * @param spec1 Starting time specification
  * @param spec2 Ending time specification
  * @return Two element array containing Calendar objects
  */
 public static DateTime[] getTimes(TimeSpec spec1, TimeSpec spec2)
 {
    if (spec1.type == TYPE_START || spec2.type == TYPE_END)
    {
       throw new ArgumentException("Recursive time specifications not allowed");
    }
    spec1.context = spec2;
    spec2.context = spec1;
    return new[] {
                    spec1.getTime(),
                    spec2.getTime()
                 };
 }