/// <summary> /// Use this static method to resolve relative time references and obtain the corresponding /// timestamps (seconds since epoch). Example: /// <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(); /// long[] ts = TimeSpec.GetTimestamps(specStart, specEnd); /// </pre> /// </summary> /// <param name="spec1">Starting time specification</param> /// <param name="spec2">Ending time specification</param> /// <returns>array containing two timestamps (in seconds since epoch)</returns> public static long[] GetTimestamps(TimeSpec spec1, TimeSpec spec2) { DateTime[] gcs = GetTimes(spec1, spec2); return new[] { Util.GetTimestamp(gcs[0]), Util.GetTimestamp(gcs[1]) }; }
/// <summary> /// Constructs TimeParser instance from the given input string. /// </summary> /// <param name="dateString">time specification string as described in detail on the rrdfetch man page</param> public TimeParser(String dateString) { scanner = new TimeScanner(dateString); spec = new TimeSpec(dateString); }
/// <summary> /// Use this static method to resolve relative time references and obtain the corresponding /// DateTime objects. Example: /// <code> /// TimeParser pStart = new TimeParser("now-1month"); // starting time /// TimeParser pEnd = new TimeParser("start+1week"); // ending time /// TimeSpec specStart = pStart.Parse(); /// TimeSpec specEnd = pEnd.Parse(); /// DateTime[] gc = TimeSpec.GetTimes(specStart, specEnd); /// </code> /// </summary> /// <param name="spec1">Starting time specification</param> /// <param name="spec2">Ending time specification</param> /// <returns>Two element array containing DateTime objects</returns> public static DateTime[] GetTimes(TimeSpec spec1, TimeSpec spec2) { if (spec1.Type == TimeSpecType.Start || spec2.Type == TimeSpecType.End) { throw new RrdException("Recursive time specifications not allowed"); } spec1.context = spec2; spec2.context = spec1; return new[] { spec1.GetTime(), spec2.GetTime() }; }