Beispiel #1
0
 public static TimeSpan?StringToNullableTimeSpan(string str)
 {
     if (StringTimeSpanDeterminer.Is(str))
     {
         return(StringTimeSpanDeterminer.To(str));
     }
     if (TimeSpan.TryParse(str, out var dateTimeOffset))
     {
         return(dateTimeOffset);
     }
     return(null);
 }
Beispiel #2
0
 public static TimeSpan ObjectToTimeSpan(object obj, TimeSpan defaultVal = default)
 {
     if (obj is null)
     {
         return(defaultVal);
     }
     if (obj is string str)
     {
         return(StringToTimeSpan(str, defaultVal));
     }
     str = obj.ToString();
     if (StringTimeSpanDeterminer.Is(str))
     {
         return(StringToTimeSpan(str, defaultVal));
     }
     return(TimeSpan.TryParse(str, out var timeSpan) ? timeSpan : defaultVal);
 }
 /// <summary>
 /// Is TImeSpan
 /// </summary>
 /// <param name="str"></param>
 /// <returns></returns>
 public static bool IsTimeSpan(this string str) => StringTimeSpanDeterminer.Is(str);
Beispiel #4
0
 public static bool __timeSpanIs(string s, Type type, Action <object> action, string format, IFormatProvider provider) =>
 type == TypeClass.TimeSpanClazz && format is null
         ? StringTimeSpanDeterminer.Is(s, provider, ValueConverter.ConvertAct <TimeSpan>(action))
         : StringTimeSpanDeterminer.Exact.Is(s, format, provider, ValueConverter.ConvertAct <TimeSpan>(action));