/// <summary>
        /// Gets the date.
        /// </summary>
        /// <param name="bytes">The bytes.</param>
        /// <param name="index">The index.</param>
        /// <returns>TimeZoneDate</returns>
        private static TimeZoneDate GetDate(byte[] bytes, Int32 index)
        {
            TimeZoneDate TimeChange = new TimeZoneDate();

            //int Year = BitConverter.ToInt16(bytes, index);
            index           += LENGTH_WORD;
            TimeChange.Month = BitConverter.ToInt16(bytes, index);

            index += LENGTH_WORD;
            TimeChange.DayOfWeek = (DayOfWeek)BitConverter.ToInt16(bytes, index);

            index += LENGTH_WORD;
            TimeChange.WeekOfMonth = BitConverter.ToInt16(bytes, index) - 1;

            index += LENGTH_WORD;
            int Hours = BitConverter.ToInt16(bytes, index);

            index += LENGTH_WORD;
            int Minutes = BitConverter.ToInt16(bytes, index);

            index += LENGTH_WORD;
            int Seconds = BitConverter.ToInt16(bytes, index);

            //index += LENGTH_WORD;
            //int Milliseconds = BitConverter.ToInt16(bytes, index);

            TimeChange.TimeOfDay = new TimeSpan(Hours, Minutes, Seconds);

            return(TimeChange);
        }
        /// <summary>
        /// Gets the date time.
        /// </summary>
        /// <param name="TimeChange">The time change.</param>
        /// <param name="year">The year.</param>
        /// <returns></returns>
        private DateTime GetDateTime(TimeZoneDate TimeChange, int year)
        {
            DateTime ChangeDay;
            int      MonthOffset = 0;

            if (TimeChange.WeekOfMonth == 4)
            {
                int LastDay = DateTime.DaysInMonth(year, TimeChange.Month);
                ChangeDay = new DateTime(year, TimeChange.Month, LastDay);

                int MonthEnd = (int)ChangeDay.DayOfWeek;
                int WeekDay  = (int)TimeChange.DayOfWeek;

                if (MonthEnd != WeekDay)
                {
                    if (MonthEnd > WeekDay)
                    {
                        MonthOffset = 0 - (MonthEnd - WeekDay);
                    }
                    else
                    {
                        MonthOffset = 0 - (MonthEnd + 7 - WeekDay);
                    }
                }
            }
            else
            {
                ChangeDay = new DateTime(year, TimeChange.Month, 1);

                int MonthStart = (int)ChangeDay.DayOfWeek;
                int WeekDay    = (int)TimeChange.DayOfWeek;

                if (MonthStart != WeekDay)
                {
                    if (WeekDay > MonthStart)
                    {
                        MonthOffset = WeekDay - MonthStart;
                    }
                    else
                    {
                        MonthOffset = WeekDay + 7 - MonthStart;
                    }
                }
                MonthOffset += 7 * TimeChange.WeekOfMonth;
            }
            ChangeDay = ChangeDay.AddDays(MonthOffset);
            ChangeDay = ChangeDay.Add(TimeChange.TimeOfDay);

            return(ChangeDay);
        }
Beispiel #3
0
    /// <summary>
    /// Gets the date.
    /// </summary>
    /// <param name="bytes">The bytes.</param>
    /// <param name="index">The index.</param>
    /// <returns>TimeZoneDate</returns>
    private static TimeZoneDate GetDate(byte[] bytes, Int32 index)
    {
      TimeZoneDate TimeChange = new TimeZoneDate();

      //int Year = BitConverter.ToInt16(bytes, index);
      index += LENGTH_WORD;
      TimeChange.Month = BitConverter.ToInt16(bytes, index);

      index += LENGTH_WORD;
      TimeChange.DayOfWeek = (DayOfWeek)BitConverter.ToInt16(bytes, index);

      index += LENGTH_WORD;
      TimeChange.WeekOfMonth = BitConverter.ToInt16(bytes, index) - 1;

      index += LENGTH_WORD;
      int Hours = BitConverter.ToInt16(bytes, index);

      index += LENGTH_WORD;
      int Minutes = BitConverter.ToInt16(bytes, index);

      index += LENGTH_WORD;
      int Seconds = BitConverter.ToInt16(bytes, index);

      //index += LENGTH_WORD;
      //int Milliseconds = BitConverter.ToInt16(bytes, index);

      TimeChange.TimeOfDay = new TimeSpan(Hours, Minutes, Seconds);

      return TimeChange;
    }
Beispiel #4
0
    /// <summary>
    /// Gets the date time.
    /// </summary>
    /// <param name="TimeChange">The time change.</param>
    /// <param name="year">The year.</param>
    /// <returns></returns>
    private DateTime GetDateTime(TimeZoneDate TimeChange, int year)
    {
      DateTime ChangeDay;
      int MonthOffset = 0;

      if (TimeChange.WeekOfMonth == 4)
      {
        int LastDay = DateTime.DaysInMonth(year, TimeChange.Month);
        ChangeDay = new DateTime(year, TimeChange.Month, LastDay);

        int MonthEnd = (int)ChangeDay.DayOfWeek;
        int WeekDay = (int)TimeChange.DayOfWeek;

        if (MonthEnd != WeekDay)
        {
          if (MonthEnd > WeekDay)
          {
            MonthOffset = 0 - (MonthEnd - WeekDay);
          }
          else
          {
            MonthOffset = 0 - (MonthEnd + 7 - WeekDay);
          }
        }
      }
      else
      {
        ChangeDay = new DateTime(year, TimeChange.Month, 1);

        int MonthStart = (int)ChangeDay.DayOfWeek;
        int WeekDay = (int)TimeChange.DayOfWeek;

        if (MonthStart != WeekDay)
        {
          if (WeekDay > MonthStart)
          {
            MonthOffset = WeekDay - MonthStart;
          }
          else
          {
            MonthOffset = WeekDay + 7 - MonthStart;
          }
        }
        MonthOffset += 7 * TimeChange.WeekOfMonth;
      }
      ChangeDay = ChangeDay.AddDays(MonthOffset);
      ChangeDay = ChangeDay.Add(TimeChange.TimeOfDay);

      return ChangeDay;
    }