public static DateTime?StringToNullableDateTime(string str) { if (StringDateTimeDeterminer.Is(str)) { return(StringDateTimeDeterminer.To(str)); } if (DateTime.TryParse(str, out var dateTime)) { return(dateTime); } return(null); }
protected override bool IsValidImpl(object value) { if (VerifiableMember.MemberType == TypeClass.DateTimeClazz || VerifiableMember.MemberType == TypeClass.DateTimeNullableClazz) { return(true); } if (value is DateTime) { return(true); } if (value is string strValue) { return(StringDateTimeDeterminer.Is(strValue, _style)); } return(StringDateTimeDeterminer.Is(value.ToString(), _style)); }
public static DateTime ObjectToDateTime(object obj, DateTime defaultVal = default) { if (obj is null) { return(defaultVal); } if (obj is string str) { return(StringToDateTime(str, defaultVal)); } str = obj.ToString(); if (StringDateTimeDeterminer.Is(str)) { return(StringToDateTime(str, defaultVal)); } try { return(Convert.ToDateTime(obj)); } catch { return(defaultVal); } }
/// <summary> /// Is DateTime /// </summary> /// <param name="str"></param> /// <returns></returns> public static bool IsDateTime(this string str) => StringDateTimeDeterminer.Is(str);
public static bool __dateTimeIs(string s, Type type, Action <object> action, string format, DateTimeStyles?dateTimeStyle, IFormatProvider provider) => type == TypeClass.DateTimeClazz && (format is null ? StringDateTimeDeterminer.Is(s, dateTimeStyle ?? DateTimeStyles.None, provider, ValueConverter.ConvertAct <DateTime>(action)) : StringDateTimeDeterminer.Exact.Is(s, format, dateTimeStyle ?? DateTimeStyles.None, provider, ValueConverter.ConvertAct <DateTime>(action)));