Issue Details (XML | Word | Printable)

Key: QRTZNET-105
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Marko Lahma
Reporter: Marko Lahma
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Quartz.NET

CronExpression fails if nth weekday of month is used and expression passes year

Created: 18/Apr/08 02:56 PM   Updated: 01/May/08 03:53 AM
Component/s: Triggers
Affects Version/s: None
Fix Version/s: 1.0 RC 1


 Description  « Hide
From the mailing list:

It's seem have a bug in cronexpress.cs file.

 else if (nthdayOfWeek != 0)
                   {
                       // are we looking for the Nth XXX day in the
month?
                       int dow = ((int) daysOfWeek.First()); //
desired
                       // d-o-w
                       int cDow = ((int) d.DayOfWeek) + 1; // current
d-o-w
                       int daysToAdd = 0;
                       if (cDow < dow)
                       {
                           daysToAdd = dow - cDow;
                       }
                       else if (cDow > dow)
                       {
                           daysToAdd = dow + (7 - cDow);
                       }

                       bool dayShifted = false;
                       if (daysToAdd > 0)
                       {
                           dayShifted = true;
                       }

                       day += daysToAdd;
                       int weekOfMonth = day/7;
                       if (day%7 > 0)
                       {
                           weekOfMonth++;
                       }

                       daysToAdd = (nthdayOfWeek - weekOfMonth)*7;
                       day += daysToAdd;
                       if (daysToAdd < 0 || day >
GetLastDayOfMonth(mon, d.Year))
                       {
                           //it's seem have a bug. here is right:
                           // if (mon == 12)
                           //{
                               d = new DateTime(d.Year, mon - 11, 1,
0, 0, 0).AddYears(1);
                           //}
                           //else
                           //{
                               d = new DateTime(d.Year, mon + 1, 1,
0, 0, 0);
                           //}

                           d = new DateTime(d.Year, mon + 1, 1, 0, 0,
0);
                           // we are promoting the month
                           continue;
                       }
                       else if (daysToAdd > 0 || dayShifted)
                       {
                           d = new DateTime(d.Year, mon, day, 0, 0,
0);
                           // we are NOT promoting the month
                           continue;
                       }
                   }

thanks

Michael

 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
There are no comments yet on this issue.