/// <summary> /// 時間封包解碼(解碼時間) /// </summary> /// <param name="buffer">ZBuffer類別</param> /// <returns>返回值: DateTime結構</returns> internal static DateTime GetDateTime(PacketBuffer buffer) { int iHour = ((buffer[1] == 35) ? 0 : 12); buffer.Position += 4; ushort TimeByte = (ushort)((buffer[0] << 8) + buffer[1]); iHour += BitConvert.GetValue(TimeByte, 12, 4); iHour = (iHour < 0 || iHour > 23) ? 0 : iHour; int iMinute = BitConvert.GetValue(TimeByte, 6, 6); iMinute = (iMinute < 0 || iMinute > 59) ? 0 : iMinute; int iSecond = BitConvert.GetValue(TimeByte, 0, 6); iSecond = (iSecond < 0 || iSecond > 59) ? 0 : iSecond; buffer.Position += 2; TimeByte = (ushort)((buffer[0] << 8) + buffer[1]); int iYear = BitConvert.GetValue(TimeByte, 9, 7) + 1990; int iMonth = BitConvert.GetValue(TimeByte, 5, 4); int iDay = BitConvert.GetValue(TimeByte, 0, 5); iMonth = (iMonth < 1) ? 1 : (iMonth > 12) ? 12 : iMonth; int iMaxDay = DateTime.DaysInMonth(iYear, iMonth); iDay = (iDay < 1) ? 1 : (iDay > iMaxDay) ? iMaxDay : iDay; buffer.Position += 2; return(new DateTime(iYear, iMonth, iDay, iHour, iMinute, iSecond)); }
/// <summary> /// 股票即時資訊時間解碼 /// </summary> /// <param name="buffer">ZBuffer類別</param> /// <returns>返回值: DateTime結構</returns> internal static DateTime GetTime(PacketBuffer buffer) { int hh = 0, mm = 0, ss = 0; ushort TimeByte = (ushort)((buffer[0] << 8) + buffer[1]); hh = (BitConvert.GetValue(TimeByte, 12, 3) + 9); hh = (hh < 0 || hh > 23) ? 0 : hh; mm = BitConvert.GetValue(TimeByte, 6, 6); mm = (mm < 0 || mm > 59) ? 0 : mm; ss = BitConvert.GetValue(TimeByte, 0, 6); ss = (ss < 0 || ss > 59) ? 0 : ss; buffer.Position += 2; return(__cToday.AddSeconds(hh * 3600 + mm * 60 + ss)); }
/// <summary> /// 時間封包解碼(解碼交易日期) /// </summary> /// <param name="buffer">ZBuffer類別</param> /// <returns>返回值: DateTime結構</returns> internal static DateTime GetDate(PacketBuffer buffer) { ushort TimeByte = (ushort)((buffer[0] << 8) + buffer[1]); int iYear = BitConvert.GetValue(TimeByte, 9, 7) + 1990; int iMonth = BitConvert.GetValue(TimeByte, 5, 4); int iDay = BitConvert.GetValue(TimeByte, 0, 5); buffer.Position += 2; iMonth = (iMonth < 1) ? 1 : (iMonth > 12) ? 12 : iMonth; int iMaxDay = DateTime.DaysInMonth(iYear, iMonth); iDay = (iDay < 1) ? 1 : (iDay > iMaxDay) ? iMaxDay : iDay; return(new DateTime(iYear, iMonth, iDay)); }
/// <summary> /// 股票即時資訊時間解碼(解碼時間 00:00:00 ~ 23:59:59) /// </summary> /// <param name="buffer">ZBuffer類別</param> /// <returns>返回值: DateTime結構</returns> internal static DateTime GetSpecial(PacketBuffer buffer) { int hh = 0, mm = 0, ss = 0; int TimeByte = (buffer[0] << 16) + (buffer[1] << 8) + buffer[2]; hh = BitConvert.GetValue(TimeByte, 19, 5); hh = (hh < 0 || hh > 23) ? 0 : hh; hh = (hh < 15) ? 24 + hh : hh; mm = BitConvert.GetValue(TimeByte, 13, 6); mm = (mm < 0 || mm > 59) ? 0 : mm; ss = BitConvert.GetValue(TimeByte, 7, 6); ss = (ss < 0 || ss > 59) ? 0 : ss; buffer.Position += 3; return(__cToday.AddSeconds(hh * 3600 + mm * 60 + ss)); }