public static DateTime ToDateTime(byte[] data, int start, UInt16Swap int16Swap, DateTimeType dateTimeType) { ushort year, moth, day, hour, min, sec; year = ToUInt16(data, start, int16Swap); moth = ToUInt16(data, start + 2, int16Swap); day = ToUInt16(data, start + 4, int16Swap); hour = ToUInt16(data, start + 6, int16Swap); min = ToUInt16(data, start + 8, int16Swap); sec = ToUInt16(data, start + 10, int16Swap); if (year <= 99) { year += 2000; } try { return(new DateTime(year, moth, day, hour, min, sec)); } catch (Exception) { return(DateTime.MinValue); } }
public static byte[] GetBytes(DateTime dt, UInt16Swap uInt16Swap, DateTimeType dateTimeType) { ushort year, moth, day, hour, min, sec; year = (ushort)dt.Year; moth = (ushort)dt.Month; day = (ushort)dt.Day; hour = (ushort)dt.Hour; min = (ushort)dt.Minute; sec = (ushort)dt.Second; switch (dateTimeType) { case DateTimeType.Short: year = (ushort)(year - 2000); break; } var b = new List <byte>(); b.AddRange(GetBytes(year, uInt16Swap)); b.AddRange(GetBytes(moth, uInt16Swap)); b.AddRange(GetBytes(day, uInt16Swap)); b.AddRange(GetBytes(hour, uInt16Swap)); b.AddRange(GetBytes(min, uInt16Swap)); b.AddRange(GetBytes(sec, uInt16Swap)); return(b.ToArray()); }
public static ItemsBase[] BuildList(UInt16Swap swap, DateTimeType type, string[] strName) { if (strName == null || strName.Length <= 0) { return(null); } var lst = new List <ItemsBase>(strName.Length); for (int i = 0; i < strName.Length; i++) { lst.Add(new DateTimeItem(strName[i], type, swap)); } return(lst.ToArray()); }
public static UInt16 ToUInt16(byte[] data, int start, UInt16Swap swap) { ushort r = 0; switch (swap) { case UInt16Swap.LowBeforce: r = BitConverter.ToUInt16(data, start); break; case UInt16Swap.HightBefore: r = (ushort)(data[start] * 256 + data[start + 1]); break; } return(r); }
public static byte[] GetBytes(UInt16 value, UInt16Swap swap) { byte[] r = null; switch (swap) { case UInt16Swap.LowBeforce: r = BitConverter.GetBytes(value); break; case UInt16Swap.HightBefore: r = new byte[2]; r[0] = (byte)(value / 256); r[1] = (byte)(value % 256); break; } return(r); }
public DateTimeItem(string text, DateTimeType swap, UInt16Swap intswap) : base(text) { SwapType = swap; UInt16SwapType = intswap; base.DefaultValue = DateTime.MinValue; }
public UInt16Item(string text, UInt16Swap swap) : base(text) { SwapType = swap; }