public static TOD Parse(string str) { TOD ret = null; if (!TryParse(str, out ret)) { throw new FormatException("Cannot parse TOD object!"); } return(ret); }
public static bool TryParse(string s, out TOD tod) { uint num; TimeSpan span; if (TryParseToTicks(s, out num)) { tod = new TOD(num); return(true); } if (PlcOpenDateConverterBase.TryParseTimeSpan(s, out span)) { tod = new TOD(span); return(true); } tod = null; return(false); }
public static bool TryConvert(TOD date, Type targetType, out object targetValue) { targetValue = null; if (targetType == typeof(TimeSpan)) { targetValue = date.Time; } else if (targetType == typeof(uint)) { targetValue = date.Ticks; } else if (targetType == typeof(long)) { targetValue = date.Ticks; } else if (targetType == typeof(string)) { targetValue = date.ToString(); } return(targetValue != null); }
public static bool TryConvert(object source, out TOD timeOfDay) { timeOfDay = null; if (source.GetType() == typeof(long)) { timeOfDay = Create((long)source); } else if (source.GetType() == typeof(uint)) { timeOfDay = Create((uint)source); } else if (source.GetType() == typeof(TimeSpan)) { timeOfDay = Create((TimeSpan)source); } else if (source.GetType() == typeof(string)) { TryParse((string)source, out timeOfDay); } return(timeOfDay != null); }
public static byte[] GetBytes(TOD tod) => BitConverter.GetBytes(tod.Ticks);
public static bool TryParse(string str, out TOD ret) => PlcOpenTODConverter.TryParse(str, out ret);