/// <summary> /// Determines if the is Time Zone currently on Daylight Saving Time /// </summary> /// <param name="TZIData"></param> /// <returns></returns> private bool IsOnDST(TZI TZIData) { // Get the current time (GMT) DateTime currentDate = DateTime.UtcNow; // Get the end date for the current year and convert to GMT (important!) DateTime standardDate = ConvertSystemTime(TZIData.StandardDate, currentDate.Year); DateTime standardDateGMT = standardDate.AddMinutes(TZIData.DaylightBias + TZIData.Bias); // Determine the current (or next) end date if (currentDate > standardDateGMT) { standardDate = ConvertSystemTime(TZIData.StandardDate, currentDate.Year+1); } // Determine the current (or next) start date DateTime daylightDate; if (TZIData.StandardDate.wMonth > TZIData.DaylightDate.wMonth) { // Northern hemisphere daylightDate = ConvertSystemTime(TZIData.DaylightDate, standardDate.Year); } else { // Southern hemisphere daylightDate = ConvertSystemTime(TZIData.DaylightDate, standardDate.Year-1); } DateTime daylightDateGMT = daylightDate.AddMinutes(TZIData.StandardBias + TZIData.Bias); return daylightDateGMT <= currentDate && currentDate <= standardDateGMT; }
/// <summary> /// Decodes the Time Zone Information structure from the byte array /// </summary> /// <param name="bytes"></param> /// <returns></returns> private TZI GetTZI(byte[] bytes) { if (bytes == null || bytes.Length < Marshal.SizeOf(typeof(TZI))) throw new Exception("TZI byte array is not a valid size"); TZI currentTZI = new TZI(); GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned); IntPtr buffer = handle.AddrOfPinnedObject(); currentTZI = (TZI) Marshal.PtrToStructure (buffer, typeof(TZI)); handle.Free(); return currentTZI; }