public static TimeSpan? TryParseExactNullable(string value, IEnumerable<string> formats, IFormatProvider provider, TimeSpanStyles styles) { TimeSpan result; if (!TimeSpan.TryParseExact(value, formats.ToArray(), provider, styles, out result)) return null; return result; }
public static TimeSpan? TryParseExactNullable(string value, string format, IFormatProvider provider, TimeSpanStyles styles) { TimeSpan result; if (!TimeSpan.TryParseExact(value, format, provider, styles, out result)) return null; return result; }
internal static TimeSpan ParseExactMultiple(string input, string[] formats, IFormatProvider formatProvider, TimeSpanStyles styles) { TimeSpanResult result = new TimeSpanResult(); result.Init(TimeSpanThrowStyle.All); if (!TryParseExactMultipleTimeSpan(input, formats, formatProvider, styles, ref result)) { throw result.GetTimeSpanParseException(); } return result.parsedTimeSpan; }
public TimeSpan ParseExactCulture(IEnumerable <string> formats, TimeSpanStyles styles, TimeSpan defaultValue = default(TimeSpan)) { return(ParseExact(formats, CultureInfo.CurrentCulture, styles, defaultValue)); }
private static bool TryParseExactTimeSpan(string input, string format, IFormatProvider formatProvider, TimeSpanStyles styles, ref TimeSpanResult result) { if (input == null) { result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, "input"); return false; } if (format == null) { result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, "format"); return false; } if (format.Length == 0) { result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier"); return false; } if (format.Length != 1) { return TryParseByFormat(input, format, styles, ref result); } TimeSpanStandardStyles none = TimeSpanStandardStyles.None; if (((format[0] == 'c') || (format[0] == 't')) || (format[0] == 'T')) { return TryParseTimeSpanConstant(input, ref result); } if (format[0] == 'g') { none = TimeSpanStandardStyles.Localized; } else if (format[0] == 'G') { none = TimeSpanStandardStyles.RequireFull | TimeSpanStandardStyles.Localized; } else { result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier"); return false; } return TryParseTimeSpan(input, none, formatProvider, ref result); }
public static Boolean TryParseTimeSpanExactMultiple(String value, String[] formats, IFormatProvider provider, TimeSpanStyles styles, out TimeSpan result) { return FormatProvider.TimeSpanParse.TryParseExactMultiple(value, formats, provider, styles, out result); }
// // TryParseExactMultipleTimeSpan // // Actions: Common private ParseExactMultiple method called by both ParseExactMultiple and TryParseExactMultiple // private static Boolean TryParseExactMultipleTimeSpan(String input, String[] formats, IFormatProvider formatProvider, TimeSpanStyles styles, ref TimeSpanResult result) { if (input == null) { result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, nameof(input)); return false; } if (formats == null) { result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, nameof(formats)); return false; } if (input.Length == 0) { result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan"); return false; } if (formats.Length == 0) { result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier"); return false; } // // Do a loop through the provided formats and see if we can parse succesfully in // one of the formats. // for (int i = 0; i < formats.Length; i++) { if (formats[i] == null || formats[i].Length == 0) { result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier"); return false; } // Create a new non-throwing result each time to ensure the runs are independent. TimeSpanResult innerResult = new TimeSpanResult(); innerResult.Init(TimeSpanThrowStyle.None); if(TryParseExactTimeSpan(input, formats[i], formatProvider, styles, ref innerResult)) { result.parsedTimeSpan = innerResult.parsedTimeSpan; return true; } } result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan"); return (false); }
public TimeSpan? ParseExactInvariant(IEnumerable<string> formats, TimeSpanStyles styles = TimeSpanStyles.None) { return ParseExact(formats, CultureInfo.InvariantCulture, styles); }
public TimeSpan ParseExact(IEnumerable<string> formats, IFormatProvider provider, TimeSpanStyles styles, TimeSpan defaultValue = default(TimeSpan)) { return TimeSpanStringParser.TryParseExactDefault(_input, formats, provider, styles, defaultValue); }
public static bool TryParseExact(string input, string[] formats, IFormatProvider provider, TimeSpanStyles styles, out DateTimeSpan result) => DateTimeSpanParse.TryParseExactMultiple(input, formats, provider, styles, out result);
/// <summary> /// The <see cref="TimeSpanStyles"/> to use when type converting. /// This is used when doing <see cref="TimeSpan"/> converting. /// </summary> /// <param name="timeSpanStyles">The time span styles.</param> public virtual MemberMap TimespanStyles(TimeSpanStyles timeSpanStyles) { memberMap.Data.TypeConverterOptions.TimeSpanStyle = timeSpanStyles; return(memberMap); }
public static bool TryParseExact([NotNullWhen(true)] string?input, [NotNullWhen(true)] string?format, IFormatProvider?formatProvider, TimeSpanStyles styles, out TimeSpan result) { ValidateStyles(styles, nameof(styles)); if (input == null || format == null) { result = default; return(false); } return(TimeSpanParse.TryParseExact(input, format, formatProvider, styles, out result)); }
/// <summary> /// 将字符串分析为Timespan /// </summary> /// <param name="value"></param> /// <returns></returns> public static TimeSpan ToTimeSpanExact(this string value, string[] format, IFormatProvider formatProvider = null, TimeSpanStyles styles = TimeSpanStyles.None) { TimeSpan ts; if (TimeSpan.TryParseExact(value, format, formatProvider, styles, out ts)) { return(ts); } return(TimeSpan.Zero); }
public static TimeSpan ParseExact(ReadOnlySpan <char> input, ReadOnlySpan <char> format, IFormatProvider?formatProvider, TimeSpanStyles styles = TimeSpanStyles.None) { ValidateStyles(styles, nameof(styles)); return(TimeSpanParse.ParseExact(input, format, formatProvider, styles)); }
public static TimeSpan ParseExact(string input, string format, IFormatProvider?formatProvider, TimeSpanStyles styles) { ValidateStyles(styles, nameof(styles)); if (input == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input); } if (format == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.format); } return(TimeSpanParse.ParseExact(input, format, formatProvider, styles)); }
public static bool TryParseExact(ReadOnlySpan <char> input, string?[]?formats, IFormatProvider?formatProvider, TimeSpanStyles styles, out TimeSpan result) { ValidateStyles(styles, nameof(styles)); return(TimeSpanParse.TryParseExactMultiple(input, formats, formatProvider, styles, out result)); }
public static bool TryParseExact(string?input, string?[]?formats, IFormatProvider?formatProvider, TimeSpanStyles styles, out TimeSpan result) { ValidateStyles(styles, nameof(styles)); if (input == null) { result = default; return(false); } return(TimeSpanParse.TryParseExactMultiple(input, formats, formatProvider, styles, out result)); }
public TimeSpan ParseExact(string format, IFormatProvider provider, TimeSpanStyles styles = TimeSpanStyles.None) { return(TimeSpan.ParseExact(_input, format, provider, styles)); }
public static TimeSpan TryParseExactDefault(string value, IEnumerable<string> formats, IFormatProvider provider, TimeSpanStyles styles, TimeSpan defaultValue) { TimeSpan result; return !TimeSpan.TryParseExact(value, formats.ToArray(), provider, styles, out result) ? defaultValue : result; }
public TimeSpan ParseExact(IEnumerable <string> formats, IFormatProvider provider, TimeSpanStyles styles = TimeSpanStyles.None) { return(TimeSpan.ParseExact(_input, formats.ToArray(), provider, styles)); }
public TimeSpan? ParseExactCulture(string format, TimeSpanStyles styles = TimeSpanStyles.None) { return ParseExact(format, CultureInfo.CurrentCulture, styles); }
public TimeSpan ParseExactCulture(string format, TimeSpanStyles styles = TimeSpanStyles.None) { return(ParseExact(format, CultureInfo.CurrentCulture, styles)); }
void TryParseExactHelper (string input, string [] formats, bool error, string expected, IFormatProvider formatProvider = null, TimeSpanStyles styles = TimeSpanStyles.None) { TimeSpan result; bool success; success = TimeSpan.TryParseExact (input, formats, formatProvider, styles, out result); Assert.AreEqual (!error, success); if (!error) Assert.AreEqual (expected, result.ToString ()); }
public TimeSpan ParseExactInvariant(string format, TimeSpanStyles styles = TimeSpanStyles.None) { return(ParseExact(format, CultureInfo.InvariantCulture, styles)); }
public static TimeSpan ParseTimeSpanExact(String value, String format, IFormatProvider provider, TimeSpanStyles styles) { return FormatProvider.TimeSpanParse.ParseExact(value, format, provider, styles); }
public TimeSpan ParseExactInvariant(IEnumerable <string> formats, TimeSpanStyles styles = TimeSpanStyles.None) { return(ParseExact(formats, CultureInfo.InvariantCulture, styles)); }
// // TryParseExactTimeSpan // // Actions: Common private ParseExact method called by both ParseExact and TryParseExact // private static Boolean TryParseExactTimeSpan(String input, String format, IFormatProvider formatProvider, TimeSpanStyles styles, ref TimeSpanResult result) { if (input == null) { result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, nameof(input)); return false; } if (format == null) { result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, nameof(format)); return false; } if (format.Length == 0) { result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier"); return false; } if (format.Length == 1) { TimeSpanStandardStyles style = TimeSpanStandardStyles.None; if (format[0] == 'c' || format[0] == 't' || format[0] == 'T') { // fast path for legacy style TimeSpan formats. return TryParseTimeSpanConstant(input, ref result); } else if (format[0] == 'g') { style = TimeSpanStandardStyles.Localized; } else if (format[0] == 'G') { style = TimeSpanStandardStyles.Localized | TimeSpanStandardStyles.RequireFull; } else { result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier"); return false; } return TryParseTimeSpan(input, style, formatProvider, ref result); } return TryParseByFormat(input, format, styles, ref result); }
public static TimeSpan ParseExact(String input, String[] formats, IFormatProvider formatProvider, TimeSpanStyles styles) { ValidateStyles(styles, nameof(styles)); return(FormatProvider.ParseTimeSpanExactMultiple(input, formats, formatProvider, styles)); }
internal static Boolean TryParseExactMultiple(String input, String[] formats, IFormatProvider formatProvider, TimeSpanStyles styles, out TimeSpan result) { TimeSpanResult parseResult = new TimeSpanResult(); parseResult.Init(TimeSpanThrowStyle.None); if (TryParseExactMultipleTimeSpan(input, formats, formatProvider, styles, ref parseResult)) { result = parseResult.parsedTimeSpan; return true; } else { result = default(TimeSpan); return false; } }
public TimeSpan ParseExact(string format, IFormatProvider provider, TimeSpanStyles styles = TimeSpanStyles.None) { return TimeSpan.ParseExact(_input, format, provider, styles); }
private static bool TryParseExactMultipleTimeSpan(string input, string[] formats, IFormatProvider formatProvider, TimeSpanStyles styles, ref TimeSpanResult result) { if (input == null) { result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, "input"); return false; } if (formats == null) { result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, "formats"); return false; } if (input.Length == 0) { result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan"); return false; } if (formats.Length == 0) { result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier"); return false; } for (int i = 0; i < formats.Length; i++) { if ((formats[i] == null) || (formats[i].Length == 0)) { result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier"); return false; } TimeSpanResult result2 = new TimeSpanResult(); result2.Init(TimeSpanThrowStyle.None); if (TryParseExactTimeSpan(input, formats[i], formatProvider, styles, ref result2)) { result.parsedTimeSpan = result2.parsedTimeSpan; return true; } } result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan"); return false; }
public TimeSpan ParseExactCulture(IEnumerable<string> formats, TimeSpanStyles styles = TimeSpanStyles.None) { return ParseExact(formats, CultureInfo.CurrentCulture, styles); }
public static Boolean TryParseExact(String input, String[] formats, IFormatProvider formatProvider, TimeSpanStyles styles, out TimeSpan result) { ValidateStyles(styles, nameof(styles)); return(FormatProvider.TryParseTimeSpanExactMultiple(input, formats, formatProvider, styles, out result)); }
public NullableTimeSpanConverter(string format, IFormatProvider formatProvider, TimeSpanStyles timeSpanStyles) : base(new TimeSpanConverter(format, formatProvider, timeSpanStyles)) { }
public TimeSpan ParseExact(IEnumerable<string> formats, IFormatProvider provider, TimeSpanStyles styles = TimeSpanStyles.None) { return TimeSpan.ParseExact(_input, formats.ToArray(), provider, styles); }
public static TimeSpan ParseTimeSpanExact(String value, String format, IFormatProvider provider, TimeSpanStyles styles) { return(FormatProvider.TimeSpanParse.ParseExact(value, format, provider, styles)); }
public static TimeSpan TryParseExactDefault(string value, string format, IFormatProvider provider, TimeSpanStyles styles, TimeSpan defaultValue) { TimeSpan result; return !TimeSpan.TryParseExact(value, format, provider, styles, out result) ? defaultValue : result; }
public static TimeSpan ParseTimeSpanExactMultiple(String value, String[] formats, IFormatProvider provider, TimeSpanStyles styles) { return(FormatProvider.TimeSpanParse.ParseExactMultiple(value, formats, provider, styles)); }
public static Boolean TryParseTimeSpanExactMultiple(String value, String[] formats, IFormatProvider provider, TimeSpanStyles styles, out TimeSpan result) { return(FormatProvider.TimeSpanParse.TryParseExactMultiple(value, formats, provider, styles, out result)); }
public static TimeSpan ParseExact(String input, String[] formats, IFormatProvider formatProvider, TimeSpanStyles styles) { TimeSpanParse.ValidateStyles(styles, "styles"); return(TimeSpanParse.ParseExactMultiple(input, formats, formatProvider, styles)); }
public TimeSpan? ParseExact(IEnumerable<string> formats, IFormatProvider provider, TimeSpanStyles styles = TimeSpanStyles.None) { return TimeSpanStringParser.TryParseExactNullable(_input, formats, provider, styles); }
public static Boolean TryParseExact(String input, String[] formats, IFormatProvider formatProvider, TimeSpanStyles styles, out TimeSpan result) { TimeSpanParse.ValidateStyles(styles, "styles"); return(TimeSpanParse.TryParseExactMultiple(input, formats, formatProvider, styles, out result)); }
public TimeSpan? ParseExactInvariant(string format, TimeSpanStyles styles = TimeSpanStyles.None) { return ParseExact(format, CultureInfo.InvariantCulture, styles); }
/// <summary> /// Sets the time span styles that are permitted when parsing the option values to <see cref="TimeSpan" /> values. /// The default is <see cref="TimeSpanStyles.None" />. /// </summary> /// <param name="timeSpanStyles">The time span styles that are permitted when parsing the option values to <see cref="TimeSpan" /> values.</param> /// <returns>A reference to this instance for further configuration.</returns> public TimeSpanListOptionSetup <TCommandOptions> Styles(TimeSpanStyles timeSpanStyles) { this.optionParser.TimeSpanStyles = timeSpanStyles; return(this); }
void ParseExactHelper (string input, string [] formats, bool format_error, bool overflow_error, string expected, IFormatProvider formatProvider = null, TimeSpanStyles timeSpanStyles = TimeSpanStyles.None) { bool overflow_exc = false; bool format_exc = false; TimeSpan result = TimeSpan.Zero; try { result = TimeSpan.ParseExact (input, formats, formatProvider, timeSpanStyles); } catch (OverflowException) { overflow_exc = true; } catch (FormatException) { format_exc = true; } Assert.AreEqual (format_error, format_exc, "A1"); Assert.AreEqual (overflow_error, overflow_exc, "A2"); if (!overflow_exc && !format_exc) Assert.AreEqual (expected, result.ToString ()); }
public static TimeSpan ParseExact(string input, [StringSyntax(StringSyntaxAttribute.TimeSpanFormat)] string[] formats, IFormatProvider?formatProvider, TimeSpanStyles styles) { ValidateStyles(styles, nameof(styles)); if (input == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input); } return(TimeSpanParse.ParseExactMultiple(input, formats, formatProvider, styles)); }
public TimeSpan ParseExact(IEnumerable<string> formats, TimeSpanStyles styles, TimeSpan defaultValue = default(TimeSpan)) { return ParseExact(formats, CultureInfo.CurrentCulture, styles, defaultValue); }
public static TimeSpan ParseExact(ReadOnlySpan <char> input, [StringSyntax(StringSyntaxAttribute.TimeSpanFormat)] string[] formats, IFormatProvider?formatProvider, TimeSpanStyles styles = TimeSpanStyles.None) { ValidateStyles(styles, nameof(styles)); return(TimeSpanParse.ParseExactMultiple(input, formats, formatProvider, styles)); }
public TimeSpan ParseExactCulture(string format, TimeSpanStyles styles, TimeSpan defaultValue = default(TimeSpan)) { return ParseExact(format, CultureInfo.CurrentCulture, styles, defaultValue); }
public static bool TryParseExact(ReadOnlySpan <char> input, [StringSyntax(StringSyntaxAttribute.TimeSpanFormat)] ReadOnlySpan <char> format, IFormatProvider?formatProvider, TimeSpanStyles styles, out TimeSpan result) { ValidateStyles(styles, nameof(styles)); return(TimeSpanParse.TryParseExact(input, format, formatProvider, styles, out result)); }
public static TimeSpan ParseTimeSpanExactMultiple(String value, String[] formats, IFormatProvider provider, TimeSpanStyles styles) { return FormatProvider.TimeSpanParse.ParseExactMultiple(value, formats, provider, styles); }
public static bool TryParseExact([NotNullWhen(true)] string?input, [NotNullWhen(true), StringSyntax(StringSyntaxAttribute.TimeSpanFormat)] string?[]?formats, IFormatProvider?formatProvider, TimeSpanStyles styles, out TimeSpan result) { ValidateStyles(styles, nameof(styles)); if (input == null) { result = default; return(false); } return(TimeSpanParse.TryParseExactMultiple(input, formats, formatProvider, styles, out result)); }
/// <summary> /// 将字符串分析为Timespan /// </summary> /// <param name="value"></param> /// <returns></returns> public static TimeSpan ToTimeSpanExact(this string value, string[] format, IFormatProvider formatProvider = null, TimeSpanStyles styles = TimeSpanStyles.None) { TimeSpan ts; if (TimeSpan.TryParseExact(value, format, formatProvider, styles, out ts)) return ts; return TimeSpan.Zero; }
public static bool TryParseExact(ReadOnlySpan <char> input, [NotNullWhen(true), StringSyntax(StringSyntaxAttribute.TimeSpanFormat)] string?[]?formats, IFormatProvider?formatProvider, TimeSpanStyles styles, out TimeSpan result) { ValidateStyles(styles, nameof(styles)); return(TimeSpanParse.TryParseExactMultiple(input, formats, formatProvider, styles, out result)); }
// // TryParseByFormat // // Actions: Parse the TimeSpan instance using the specified format. Used by TryParseExactTimeSpan. // private static Boolean TryParseByFormat(String input, String format, TimeSpanStyles styles, ref TimeSpanResult result) { Debug.Assert(input != null, "input != null"); Debug.Assert(format != null, "format != null"); bool seenDD = false; // already processed days? bool seenHH = false; // already processed hours? bool seenMM = false; // already processed minutes? bool seenSS = false; // already processed seconds? bool seenFF = false; // already processed fraction? int dd = 0; // parsed days int hh = 0; // parsed hours int mm = 0; // parsed minutes int ss = 0; // parsed seconds int leadingZeroes = 0; // number of leading zeroes in the parsed fraction int ff = 0; // parsed fraction int i = 0; // format string position int tokenLen = 0; // length of current format token, used to update index 'i' TimeSpanTokenizer tokenizer = new TimeSpanTokenizer(); tokenizer.Init(input, -1); while (i < format.Length) { char ch = format[i]; int nextFormatChar; switch (ch) { case 'h': tokenLen = DateTimeFormat.ParseRepeatPattern(format, i, ch); if (tokenLen > 2 || seenHH || !ParseExactDigits(ref tokenizer, tokenLen, out hh)) { result.SetFailure(ParseFailureKind.Format, "Format_InvalidString"); return false; } seenHH = true; break; case 'm': tokenLen = DateTimeFormat.ParseRepeatPattern(format, i, ch); if (tokenLen > 2 || seenMM || !ParseExactDigits(ref tokenizer, tokenLen, out mm)) { result.SetFailure(ParseFailureKind.Format, "Format_InvalidString"); return false; } seenMM = true; break; case 's': tokenLen = DateTimeFormat.ParseRepeatPattern(format, i, ch); if (tokenLen > 2 || seenSS || !ParseExactDigits(ref tokenizer, tokenLen, out ss)) { result.SetFailure(ParseFailureKind.Format, "Format_InvalidString"); return false; } seenSS = true; break; case 'f': tokenLen = DateTimeFormat.ParseRepeatPattern(format, i, ch); if (tokenLen > DateTimeFormat.MaxSecondsFractionDigits || seenFF || !ParseExactDigits(ref tokenizer, tokenLen, tokenLen, out leadingZeroes, out ff)) { result.SetFailure(ParseFailureKind.Format, "Format_InvalidString"); return false; } seenFF = true; break; case 'F': tokenLen = DateTimeFormat.ParseRepeatPattern(format, i, ch); if (tokenLen > DateTimeFormat.MaxSecondsFractionDigits || seenFF) { result.SetFailure(ParseFailureKind.Format, "Format_InvalidString"); return false; } ParseExactDigits(ref tokenizer, tokenLen, tokenLen, out leadingZeroes, out ff); seenFF = true; break; case 'd': tokenLen = DateTimeFormat.ParseRepeatPattern(format, i, ch); int tmp = 0; if (tokenLen > 8 || seenDD || !ParseExactDigits(ref tokenizer, (tokenLen<2) ? 1 : tokenLen, (tokenLen<2) ? 8 : tokenLen, out tmp, out dd)) { result.SetFailure(ParseFailureKind.Format, "Format_InvalidString"); return false; } seenDD = true; break; case '\'': case '\"': StringBuilder enquotedString = new StringBuilder(); if (!DateTimeParse.TryParseQuoteString(format, i, enquotedString, out tokenLen)) { result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadQuote", ch); return false; } if (!ParseExactLiteral(ref tokenizer, enquotedString)) { result.SetFailure(ParseFailureKind.Format, "Format_InvalidString"); return false; } break; case '%': // Optional format character. // For example, format string "%d" will print day // Most of the cases, "%" can be ignored. nextFormatChar = DateTimeFormat.ParseNextChar(format, i); // nextFormatChar will be -1 if we already reach the end of the format string. // Besides, we will not allow "%%" appear in the pattern. if (nextFormatChar >= 0 && nextFormatChar != (int)'%') { tokenLen = 1; // skip the '%' and process the format character break; } else { // This means that '%' is at the end of the format string or // "%%" appears in the format string. result.SetFailure(ParseFailureKind.Format, "Format_InvalidString"); return false; } case '\\': // Escaped character. Can be used to insert character into the format string. // For example, "\d" will insert the character 'd' into the string. // nextFormatChar = DateTimeFormat.ParseNextChar(format, i); if (nextFormatChar >= 0 && tokenizer.NextChar == (char)nextFormatChar) { tokenLen = 2; } else { // This means that '\' is at the end of the format string or the literal match failed. result.SetFailure(ParseFailureKind.Format, "Format_InvalidString"); return false; } break; default: result.SetFailure(ParseFailureKind.Format, "Format_InvalidString"); return false; } i += tokenLen; } if (!tokenizer.EOL) { // the custom format didn't consume the entire input result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan"); return false; } long ticks = 0; bool positive = (styles & TimeSpanStyles.AssumeNegative) == 0; if (TryTimeToTicks(positive, new TimeSpanToken(dd), new TimeSpanToken(hh), new TimeSpanToken(mm), new TimeSpanToken(ss), new TimeSpanToken(leadingZeroes, ff), out ticks)) { if (!positive) ticks = -ticks; result.parsedTimeSpan._ticks = ticks; return true; } else { result.SetFailure(ParseFailureKind.Overflow, "Overflow_TimeSpanElementTooLarge"); return false; } }
public static TimeSpan ParseExact(String input, String format, IFormatProvider formatProvider, TimeSpanStyles styles) { TimeSpanParse.ValidateStyles(styles, nameof(styles)); return(TimeSpanParse.ParseExact(input, format, formatProvider, styles)); }
internal static TimeSpan ParseExactMultiple(String input, String[] formats, IFormatProvider formatProvider, TimeSpanStyles styles) { TimeSpanResult parseResult = new TimeSpanResult(); parseResult.Init(TimeSpanThrowStyle.All); if (TryParseExactMultipleTimeSpan(input, formats, formatProvider, styles, ref parseResult)) { return parseResult.parsedTimeSpan; } else { throw parseResult.GetTimeSpanParseException(); } }
internal static bool TryParseExactMultiple(string input, string[] formats, IFormatProvider formatProvider, TimeSpanStyles styles, out TimeSpan result) { TimeSpanResult result2 = new TimeSpanResult(); result2.Init(TimeSpanThrowStyle.None); if (TryParseExactMultipleTimeSpan(input, formats, formatProvider, styles, ref result2)) { result = result2.parsedTimeSpan; return true; } result = new TimeSpan(); return false; }
// ---- SECTION: members for internal support ---------* internal static void ValidateStyles(TimeSpanStyles style, String parameterName) { if (style != TimeSpanStyles.None && style != TimeSpanStyles.AssumeNegative) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidTimeSpanStyles"), parameterName); }
public TimeSpan ParseExactCulture(string format, TimeSpanStyles styles, TimeSpan defaultValue = default(TimeSpan)) { return(ParseExact(format, CultureInfo.CurrentCulture, styles, defaultValue)); }