/// <summary> /// To /// </summary> /// <param name="text"></param> /// <param name="impls"></param> /// <param name="formatProvider"></param> /// <returns></returns> public static TimeSpan To( string text, IEnumerable <IConversionImpl <string, TimeSpan> > impls, IFormatProvider formatProvider = null) { return(ValueConverter.ToXxx(text, (s, act) => Is(s, formatProvider.SafeDateTime(), act), impls)); }
/// <summary> /// To /// </summary> /// <param name="str"></param> /// <param name="impls"></param> /// <param name="style"></param> /// <param name="formatProvider"></param> /// <returns></returns> public static DateTimeOffset To(string str, IEnumerable <IConversionImpl <string, DateTimeOffset> > impls, DateTimeStyles style = DateTimeStyles.None, IFormatProvider formatProvider = null) { return(ValueConverter.ToXxx(str, (s, act) => Is(s, style, formatProvider.SafeDateTime(), act), impls)); }
/// <summary> /// To /// </summary> /// <param name="str"></param> /// <param name="style"></param> /// <param name="formatProvider"></param> /// <param name="defaultVal"></param> /// <returns></returns> public static DateTimeOffset To(string str, DateTimeStyles style = DateTimeStyles.None, IFormatProvider formatProvider = null, DateTimeOffset defaultVal = default) { return(DateTimeOffset.TryParse(str, formatProvider.SafeDateTime(), style, out var offset) ? offset : defaultVal); }
/// <summary> /// To /// </summary> /// <param name="str"></param> /// <param name="style"></param> /// <param name="formatProvider"></param> /// <param name="defaultVal"></param> /// <returns></returns> public static DateTime To(string str, DateTimeStyles style = DateTimeStyles.None, IFormatProvider formatProvider = null, DateTime defaultVal = default) { return(DateTime.TryParse(str, formatProvider.SafeDateTime(), style, out var dateTime) ? dateTime : defaultVal); }
/// <summary> /// To /// </summary> /// <param name="str"></param> /// <param name="format"></param> /// <param name="style"></param> /// <param name="formatProvider"></param> /// <param name="defaultVal"></param> /// <returns></returns> public static DateTime To(string str, string format, DateTimeStyles style = DateTimeStyles.None, IFormatProvider formatProvider = null, DateTime defaultVal = default) { return(DateTime.TryParseExact(str, format, formatProvider.SafeDateTime(), style, out var dateTime) ? dateTime : ValueConverter.ToXxxAgain(str, defaultVal)); }
/// <summary> /// To /// </summary> /// <param name="text"></param> /// <param name="formatProvider"></param> /// <param name="defaultVal"></param> /// <returns></returns> public static TimeSpan To( string text, IFormatProvider formatProvider = null, TimeSpan defaultVal = default) { if (text is null) { return(defaultVal); } return(TimeSpan.TryParse(text, formatProvider.SafeDateTime(), out var timeSpan) ? timeSpan : defaultVal); }
/// <summary> /// Is /// </summary> /// <param name="text"></param> /// <param name="formatProvider"></param> /// <param name="matchedCallback"></param> /// <returns></returns> public static bool Is( string text, IFormatProvider formatProvider = null, Action <TimeSpan> matchedCallback = null) { if (string.IsNullOrWhiteSpace(text)) { return(false); } return(TimeSpan.TryParse(text, formatProvider.SafeDateTime(), out var timeSpan) .IfTrueThenInvoke(matchedCallback, timeSpan)); }
/// <summary> /// Is /// </summary> /// <param name="str"></param> /// <param name="format"></param> /// <param name="formatProvider"></param> /// <param name="tsAct"></param> /// <returns></returns> public static bool Is(string str, string format, IFormatProvider formatProvider = null, Action <TimeSpan> tsAct = null) { if (string.IsNullOrWhiteSpace(str)) { return(false); } var result = TimeSpan.TryParseExact(str, format, formatProvider.SafeDateTime(), out var timeSpan); if (result) { tsAct?.Invoke(timeSpan); } return(result); }
/// <summary> /// Is /// </summary> /// <param name="text"></param> /// <param name="style"></param> /// <param name="formatProvider"></param> /// <param name="matchedCallback"></param> /// <returns></returns> public static bool Is( string text, DateTimeStyles style = DateTimeStyles.None, IFormatProvider formatProvider = null, Action <DateTimeOffset> matchedCallback = null) { if (string.IsNullOrWhiteSpace(text)) { return(false); } return(DateTimeOffset.TryParse(text, formatProvider.SafeDateTime(), style, out var dateTimeOffset) .IfFalseThenInvoke(ValueDeterminer.IsXxxAgain <DateTimeOffset>, text) .IfTrueThenInvoke(matchedCallback, dateTimeOffset)); }
/// <summary> /// Is /// </summary> /// <param name="text"></param> /// <param name="format"></param> /// <param name="style"></param> /// <param name="formatProvider"></param> /// <param name="matchedCallback"></param> /// <returns></returns> public static bool Is( string text, string format, DateTimeStyles style = DateTimeStyles.None, IFormatProvider formatProvider = null, Action <DateTime> matchedCallback = null) { if (string.IsNullOrWhiteSpace(text)) { return(false); } return(DateTime.TryParseExact(text, format, formatProvider.SafeDateTime(), style, out var dateTime) .IfTrueThenInvoke(matchedCallback, dateTime)); }
/// <summary> /// To /// </summary> /// <param name="text"></param> /// <param name="format"></param> /// <param name="style"></param> /// <param name="formatProvider"></param> /// <param name="defaultVal"></param> /// <returns></returns> public static DateTimeOffset To( string text, string format, DateTimeStyles style = DateTimeStyles.None, IFormatProvider formatProvider = null, DateTimeOffset defaultVal = default) { if (text is null) { return(defaultVal); } return(DateTimeOffset.TryParseExact(text, format, formatProvider.SafeDateTime(), style, out var offset) ? offset : defaultVal); }
/// <summary> /// Is /// </summary> /// <param name="str"></param> /// <param name="format"></param> /// <param name="style"></param> /// <param name="formatProvider"></param> /// <param name="dtAct"></param> /// <returns></returns> public static bool Is(string str, string format, DateTimeStyles style = DateTimeStyles.None, IFormatProvider formatProvider = null, Action <DateTimeOffset> dtAct = null) { if (string.IsNullOrWhiteSpace(str)) { return(false); } var result = DateTimeOffset.TryParseExact(str, format, formatProvider.SafeDateTime(), style, out var dateTimeOffset); if (result) { dtAct?.Invoke(dateTimeOffset); } return(result); }
/// <summary> /// Is /// </summary> /// <param name="str"></param> /// <param name="style"></param> /// <param name="formatProvider"></param> /// <param name="dtAct"></param> /// <returns></returns> public static bool Is(string str, DateTimeStyles style = DateTimeStyles.None, IFormatProvider formatProvider = null, Action <DateTime> dtAct = null) { if (string.IsNullOrWhiteSpace(str)) { return(false); } var result = DateTime.TryParse(str, formatProvider.SafeDateTime(), style, out var dateTime); if (!result) { result = ValueDeterminer.IsXxxAgain <DateTime>(str); } if (result) { dtAct?.Invoke(dateTime); } return(result); }
/// <summary> /// To /// </summary> /// <param name="str"></param> /// <param name="formatProvider"></param> /// <param name="defaultVal"></param> /// <returns></returns> public static TimeSpan To(string str, IFormatProvider formatProvider = null, TimeSpan defaultVal = default) => TimeSpan.TryParse(str, formatProvider.SafeDateTime(), out var timeSpan) ? timeSpan : defaultVal;
/// <summary> /// To /// </summary> /// <param name="str"></param> /// <param name="format"></param> /// <param name="impls"></param> /// <param name="formatProvider"></param> /// <returns></returns> public static TimeSpan To(string str, string format, IEnumerable <IConversionImpl <string, TimeSpan> > impls, IFormatProvider formatProvider = null) => ValueConverter.ToXxx(str, (s, act) => Is(s, format, formatProvider.SafeDateTime(), act), impls);