Calculate the next start time of a job and store it in the job object. DaysOfMonth and DaysOfWeek are not taken into account yet.
svn path=/trunk/; revision=74315
/* Release the job list lock */
RtlReleaseResource(&JobListLock);
/* Release the job list lock */
RtlReleaseResource(&JobListLock);
- // Calculate start time
+ /* Calculate the next start time */
+ CalculateNextStartTime(pJob);
// Insert job into the start list
// Insert job into the start list
+static
+WORD
+DaysOfMonth(
+ WORD wMonth,
+ WORD wYear)
+{
+ WORD wDaysArray[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
+
+ if (wMonth == 2 && wYear % 4 == 0 && wYear % 400 != 0)
+ return 29;
+
+ return wDaysArray[wMonth];
+}
+
+
VOID
CalculateNextStartTime(PJOB pJob)
{
VOID
CalculateNextStartTime(PJOB pJob)
{
- SYSTEMTIME Time;
- DWORD_PTR JobTime;
- WORD wDay;
- BOOL bToday = FALSE;
+ SYSTEMTIME StartTime;
+ DWORD_PTR Now;
+
+ GetLocalTime(&StartTime);
+ Now = (DWORD_PTR)StartTime.wHour * 3600000 +
+ (DWORD_PTR)StartTime.wMinute * 60000;
- Now = (DWORD_PTR)Time.wHour * 3600000 +
- (DWORD_PTR)Time.wMinute * 60000;
- if (pJob->JobTime > Now)
- bToday = TRUE;
+ StartTime.wMilliseconds = 0;
+ StartTime.wSecond = 0;
+ StartTime.wHour = (WORD)(pJob->JobTime / 3600000);
+ StartTime.wMinute = (WORD)((pJob->JobTime % 3600000) / 60000);
- if (pJob->DaysOfMonth != 0)
+ /* Start the job tomorrow */
+ if (Now > pJob->JobTime)
- wDay = 0;
- for (i = Time.wDay - 1; i < 32; i++)
+ if (StartTime.wDay + 1 > DaysOfMonth(StartTime.wMonth, StartTime.wYear))
- if (pJob->DaysOfMonth && (1 << i))
+ if (StartTime.wMonth == 12)
+ StartTime.wDay = 1;
+ StartTime.wMonth = 1;
+ StartTime.wYear++;
+ else
+ {
+ StartTime.wDay = 1;
+ StartTime.wMonth++;
+ }
+ }
+ else
+ {
+ StartTime.wDay++;
- ERR("Next day this month: %hu\n", wDay);
- else if (pJob->DaysOfWeek != 0)
- {
+ ERR("Next start: %02hu:%02hu %02hu.%02hu.%hu\n", StartTime.wHour,
+ StartTime.wMinute, StartTime.wDay, StartTime.wMonth, StartTime.wYear);
+
+ SystemTimeToFileTime(&StartTime, &pJob->StartTime);
LIST_ENTRY JobEntry;
LIST_ENTRY StartEntry;
LIST_ENTRY JobEntry;
LIST_ENTRY StartEntry;
- LARGE_INTEGER StartTime;
WCHAR Name[9];
DWORD JobId;
WCHAR Name[9];
DWORD JobId;
+VOID
+CalculateNextStartTime(
+ PJOB pJob);
/* Save the job in the registry */
SaveJob(pJob);
/* Save the job in the registry */
SaveJob(pJob);
- // Calculate start time
+ /* Calculate the next start time */
+ CalculateNextStartTime(pJob);
- // Insert job into start list
+ // Insert job into the start list
+ // Update the start timer
/* Return the new job ID */
*pJobId = pJob->JobId;
/* Return the new job ID */
*pJobId = pJob->JobId;
if ((CurrentJob->JobId >= MinJobId) && (CurrentJob->JobId <= MaxJobId))
{
if ((CurrentJob->JobId >= MinJobId) && (CurrentJob->JobId <= MaxJobId))
{
- // Remove job from start list
+ // Remove job from the start list
+ // Update the start timer
/* Remove the job from the registry */
DeleteJob(CurrentJob);
/* Remove the job from the registry */
DeleteJob(CurrentJob);