Beispiel #1
0
 public ScheduleToken(RuleDayOfWeek startDay, RuleDayOfWeek endDay)
     : this(ScheduleTokenType.DayRange)
 {
     StartDay = startDay;
     EndDay = endDay;
 }
Beispiel #2
0
 public ScheduleToken(RuleDayOfWeek singleDay)
     : this(ScheduleTokenType.SingleDay)
 {
     Day = singleDay;
 }
Beispiel #3
0
 public ScheduleRule(RuleDayOfWeek days, short startMinute, short endMinute)
 {
     Days = days;
     StartMinute = startMinute;
     EndMinute = endMinute;
 }
Beispiel #4
0
 public bool IsMatch(short minute, RuleDayOfWeek day)
 {
     if (StartMinute < EndMinute)
     {
         if ((Days & day) == day && minute > StartMinute && minute < EndMinute)
         {
             return true;
         }
     }
     else
     {
         if ((Days & day) == day && minute > StartMinute)
         {
             return true;
         }
         else
         {
             if (day == RuleDayOfWeek.Sunday)
             {
                 day = RuleDayOfWeek.Saturday;
             }
             else
             {
                 day = (RuleDayOfWeek)((short)day >> 1);
             }
             if ((Days & day) == day && minute < EndMinute)
             {
                 return true;
             }
         }
     }
     return false;
 }
Beispiel #5
0
 private static RuleDayOfWeek GetDayRange(RuleDayOfWeek from, RuleDayOfWeek to)
 {
     RuleDayOfWeek totalDays = RuleDayOfWeek.None;
     int loopGuard = 0;
     while (true)
     {
         if (loopGuard++ > 500)
         {
             break;
         }
         totalDays |= from;
         if (from == to)
         {
             break;
         }
         if (from == RuleDayOfWeek.Saturday)
         {
             from = RuleDayOfWeek.Sunday;
         }
         else
         {
             from = (RuleDayOfWeek)((int)from << 1);
         }
     }
     return totalDays;
 }
Beispiel #6
0
        private static ScheduleRule ConvertHourTokenToRule(RuleDayOfWeek days, ScheduleToken hourToken)
        {
            switch (hourToken.Type)
            {
                case ScheduleTokenType.AllDay:
                case ScheduleTokenType.HourRange:
                    byte startHour = hourToken.StartHour.Value;
                    if (hourToken.StartMeridiem != HourMeridiem.None)
                    {
                        if (hourToken.StartMeridiem == HourMeridiem.AM)
                        {
                            if (startHour == 12)
                            {
                                startHour = 0;
                            }
                        }
                        else if (startHour > 0 && startHour < 12)
                        {
                            startHour += 12;
                        }
                    }
                    else if (startHour == 24)
                    {
                        startHour = 0;
                    }
                    short startMinute = (short)((startHour * 60) + (hourToken.StartMinute ?? 0));

                    byte endHour = hourToken.EndHour.Value;
                    if (hourToken.EndMeridiem != HourMeridiem.None)
                    {
                        if (hourToken.EndMeridiem == HourMeridiem.AM)
                        {
                            if (endHour == 12)
                            {
                                endHour = 0;
                            }
                        }
                        else if (endHour > 0 && endHour < 12)
                        {
                            endHour += 12;
                        }
                    }
                    else if (endHour == 24)
                    {
                        endHour = 0;
                    }
                    short endMinute = (short)((endHour * 60) + (hourToken.EndMinute ?? 0));
                    if (hourToken.EndMeridiem == HourMeridiem.PM && hourToken.StartMeridiem == HourMeridiem.None && (startMinute + (12 * 60)) < endMinute && startMinute < 1440)
                    {
                        startMinute += (12 * 60);
                    }
                    else if (hourToken.EndMeridiem == HourMeridiem.None && startMinute > endMinute && startMinute < 720 && endMinute < 720)
                    {
                        endMinute += (12 * 60);
                    }
                    return new ScheduleRule(days, startMinute, endMinute);
            }
            return null;
        }