/// <summary> /// Attempt to make a decimal hour. /// </summary> /// <param name="builder">The time span builder to updated if the value was made.</param> /// <returns>true if the decimal duration was made, false if not.</returns> bool TryMakeHour(IDurationBuilder builder) { decimal duration; if (TryMake(TryMakeSegment, TimePart.Hour, out duration)) { builder.Hour = duration; } return(TryMakeMinute(builder)); }
/// <summary> /// Attempt to make a decimal month. /// </summary> /// <param name="builder">The time span builder to updated if the value was made.</param> /// <returns>true if the decimal duration was made, false if not.</returns> bool TryMakeMonth(IDurationBuilder builder) { decimal duration; if (TryMake(TryMakeSegment, TimePart.Month, out duration)) { builder.Month = duration; } return(TryMakeDay(builder)); }
/// <summary> /// Attempt to make a decimal day. /// </summary> /// <param name="builder">The time span builder to updated if the value was made.</param> /// <returns>true if the decimal duration was made, false if not.</returns> bool TryMakeDay(IDurationBuilder builder) { decimal duration; if (TryMake(TryMakeSegment, TimePart.Day, out duration)) { builder.Day = duration; } return(TryMakeHour(builder)); }
/// <summary> /// Attempt to make a decimal month. /// </summary> /// <param name="builder">The time span builder to updated if the value was made.</param> /// <returns>true if the decimal duration was made, false if not.</returns> bool TryMakeYear(IDurationBuilder builder) { decimal duration; if (TryMake(TryMakeSegment, TimePart.Year, out duration)) { builder.Year = duration; } return(TryMakeMonth(builder)); }
/// <summary> /// Attempt to make a decimal second. /// </summary> /// <param name="builder">The time span builder to updated if the value was made.</param> /// <returns>true if the decimal duration was made, false if not.</returns> bool TryMakeSecond(IDurationBuilder builder) { decimal duration; if (TryMake(TryMakeSegment, TimePart.Second, out duration)) { builder.Second = duration; } return(TryMakeEnd()); }
/// <summary> /// Attempt to make a decimal minute. /// </summary> /// <param name="builder">The time span builder to updated if the value was made.</param> /// <returns>true if the decimal duration was made, false if not.</returns> bool TryMakeMinute(IDurationBuilder builder) { decimal duration; if (TryMake(TryMakeSegment, TimePart.Minute, out duration)) { builder.Minute = duration; } return(TryMakeSecond(builder)); }
/// <summary> /// Attempt to make a timespan from the token enumerator. /// </summary> /// <param name="builder">The builder to apply the values to.</param> /// <returns>true if a timespan could be made, false if not.</returns> internal bool TryMake(IDurationBuilder builder) { return(TryMakeYear(builder)); }
/// <summary> /// Attempt to parse the given input into a usable format. /// </summary> /// <typeparam name="T">The element type to parse the input to.</typeparam> /// <param name="input">The input string to attempt to parse.</param> /// <param name="builder">The duration builder to build the duration into.</param> /// <returns>true if the input could be parsed, false if not.</returns> public static bool TryParse <T>(string input, IDurationBuilder <T> builder) { var parser = new DurationParser(new TokenEnumerator(new StringTokenReader(input))); return(parser.TryMake(builder)); }