Exemplo n.º 1
0
        /// <summary>
        /// Tests whether this date is equal or after the date, when given weekday in given week occurs.
        /// </summary>
        /// <param name="weekNumber">Number of week. values 1, 2, 3, 4 are order of week, value 5 means last week of the month</param>
        /// <param name="dayNumber">Number of weekday, value 0 is Sunday, 1 is Monday, .... 6 is Saturday</param>
        /// <returns>Returns true, if this date is equal or is after the date given by weeknumber and daynumber</returns>
        public bool IsEqualOrAfterWeekdayInWeek(int weekNumber, int dayNumber)
        {
            GregorianDateTime vc = this;

            int[] xx = { 1, 7, 6, 5, 4, 3, 2 };

            int dowFirstDay, firstGivenWeekday, requiredGivenWeekday, lastDayInMonth;

            // prvy den mesiaca
            dowFirstDay = xx[(7 + vc.day - vc.dayOfWeek) % 7];

            // 1. x-day v mesiaci ma datum
            firstGivenWeekday = xx[(dowFirstDay - dayNumber + 7) % 7];

            // n-ty x-day ma datum
            if ((weekNumber < 0) || (weekNumber >= 5))
            {
                requiredGivenWeekday = firstGivenWeekday + 28;
                lastDayInMonth       = GregorianDateTime.GetMonthMaxDays(vc.year, vc.month);
                while (requiredGivenWeekday > lastDayInMonth)
                {
                    requiredGivenWeekday -= 7;
                }
            }
            else
            {
                requiredGivenWeekday = Convert.ToInt32(firstGivenWeekday + (weekNumber - 1) * 7);
            }

            return(vc.day >= requiredGivenWeekday);
        }
Exemplo n.º 2
0
 public void NormalizeValues(ref int y1, ref int m1, ref int d1, ref double h1)
 {
     if (h1 < 0.0)
     {
         d1--;
         h1 += 1.0;
     }
     else if (h1 >= 1.0)
     {
         h1 -= 1.0;
         d1++;
     }
     if (d1 < 1)
     {
         m1--;
         if (m1 < 1)
         {
             m1 = 12;
             y1--;
         }
         d1 = GregorianDateTime.GetMonthMaxDays(y1, m1);
     }
     else if (d1 > GregorianDateTime.GetMonthMaxDays(y1, m1))
     {
         m1++;
         if (m1 > 12)
         {
             m1 = 1;
             y1++;
         }
         d1 = 1;
     }
 }
Exemplo n.º 3
0
 public void NextDay()
 {
     day++;
     if (day > GregorianDateTime.GetMonthMaxDays(year, month))
     {
         month++;
         if (month > 12)
         {
             month = 1;
             year++;
         }
         day = 1;
     }
     dayOfWeek = (dayOfWeek + 1) % 7;
 }
Exemplo n.º 4
0
 public void PreviousDay()
 {
     day--;
     if (day < 1)
     {
         month--;
         if (month < 1)
         {
             month = 12;
             year--;
         }
         day = GregorianDateTime.GetMonthMaxDays(year, month);
     }
     dayOfWeek = (dayOfWeek + 6) % 7;
 }
Exemplo n.º 5
0
 public int GetDaylightTimeStartDate(int nYear, ref GregorianDateTime vcStart)
 {
     vcStart.day   = 1;
     vcStart.month = Convert.ToInt32(StartDst.Month);
     vcStart.year  = nYear;
     if (StartDst.Type == 1)
     {
         vcStart.day = StartDst.Day;
     }
     else
     {
         if (StartDst.Month == 5)
         {
             vcStart.day = GregorianDateTime.GetMonthMaxDays(nYear, StartDst.Month);
             vcStart.InitWeekDay();
             while (vcStart.dayOfWeek != StartDst.Day)
             {
                 vcStart.PreviousDay();
                 vcStart.dayOfWeek = (vcStart.dayOfWeek + 6) % 7;
             }
         }
         else
         {
             vcStart.day = 1;
             vcStart.InitWeekDay();
             while (vcStart.dayOfWeek != StartDst.Day)
             {
                 vcStart.NextDay();
                 vcStart.dayOfWeek = (vcStart.dayOfWeek + 1) % 7;
             }
             vcStart.day += StartDst.Week * 7;
         }
     }
     vcStart.shour = 1 / 24.0;
     return(0);
 }
Exemplo n.º 6
0
 public TResultCalendar(GCLocation loc, int nYear, int nMonth) : this()
 {
     CalculateCalendar(loc, new GregorianDateTime(nYear, nMonth, 1), GregorianDateTime.GetMonthMaxDays(nYear, nMonth));
 }