internal static ParsingResult TryParse(string input, out MetricTimeSpan timeSpan) { timeSpan = null; if (string.IsNullOrWhiteSpace(input)) { return(ParsingResult.EmptyInputString); } var match = ParsingUtilities.Match(input, Patterns); if (match == null) { return(ParsingResult.NotMatched); } int hours; if (!ParsingUtilities.ParseNonnegativeInt(match, HoursGroupName, 0, out hours)) { return(ParsingResult.Error(HoursIsOutOfRange)); } int minutes; if (!ParsingUtilities.ParseNonnegativeInt(match, MinutesGroupName, 0, out minutes)) { return(ParsingResult.Error(MinutesIsOutOfRange)); } int seconds; if (!ParsingUtilities.ParseNonnegativeInt(match, SecondsGroupName, 0, out seconds)) { return(ParsingResult.Error(SecondsIsOutOfRange)); } int milliseconds; if (!ParsingUtilities.ParseNonnegativeInt(match, MillisecondsGroupName, 0, out milliseconds)) { return(ParsingResult.Error(MillisecondsIsOutOfRange)); } timeSpan = new MetricTimeSpan(hours, minutes, seconds, milliseconds); return(ParsingResult.Parsed); }
private static long MetricTimeSpanToTicks(MetricTimeSpan timeSpan, TempoMap tempoMap) { var timeMicroseconds = timeSpan.TotalMicroseconds; if (timeMicroseconds == 0) { return(0); } var valuesCache = tempoMap.GetValuesCache <MetricTempoMapValuesCache>(); var accumulatedMicroseconds = valuesCache.Microseconds.TakeWhile(m => m.Microseconds < timeMicroseconds).LastOrDefault(); var lastAccumulatedMicroseconds = accumulatedMicroseconds?.Microseconds ?? 0; var lastTime = accumulatedMicroseconds?.Time ?? 0; var lastTicksPerMicrosecond = accumulatedMicroseconds?.TicksPerMicrosecond ?? valuesCache.DefaultTicksPerMicrosecond; return(RoundMicroseconds(lastTime + (timeMicroseconds - lastAccumulatedMicroseconds) * lastTicksPerMicrosecond)); }