public static bool TryConvert(object source, out TIME time) { time = null; if (source.GetType() == typeof(long)) { time = CreateTime((uint)source); } else if (source.GetType() == typeof(uint)) { time = CreateTime((uint)source); } else if (source.GetType() == typeof(int)) { time = CreateTime((uint)source); } else if (source.GetType() == typeof(TimeSpan)) { time = CreateTime((TimeSpan)source); } else if (source.GetType() == typeof(string)) { TryParse((string)source, out time); } return(time != null); }
public static TIME Parse(string str) { TIME ret = null; if (!TryParse(str, out ret)) { throw new FormatException("Cannot create TIME DataType!"); } return(ret); }
public static bool TryParse(string str, out TIME ret) { uint milliseconds = 0; if (PlcOpenTimeConverter.TryParseToMilliseconds(str, out milliseconds)) { ret = new TIME(milliseconds); return(true); } ret = null; return(false); }
public static bool TryParse(string s, out TIME time) { TimeSpan span; uint milliseconds = 0; if (TryParseToMilliseconds(s, out milliseconds)) { time = new TIME(milliseconds); return(true); } if (PlcOpenDateConverterBase.TryParseTimeSpan(s, out span)) { time = new TIME(span); return(true); } time = null; return(false); }
public static byte[] GetBytes(TIME time) => BitConverter.GetBytes(time.Ticks);