diff --git a/reactos/base/services/schedsvc/job.c b/reactos/base/services/schedsvc/job.c index beebc4ff158..8e7a90c8805 100644 --- a/reactos/base/services/schedsvc/job.c +++ b/reactos/base/services/schedsvc/job.c @@ -282,7 +282,8 @@ LoadJobs(VOID) /* Release the job list lock */ RtlReleaseResource(&JobListLock); - // Calculate start time + /* Calculate the next start time */ + CalculateNextStartTime(pJob); // Insert job into the start list @@ -310,38 +311,62 @@ done: } -#if 0 +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) { - SYSTEMTIME Time; - DWORD_PTR JobTime; - WORD wDay; - BOOL bToday = FALSE; + SYSTEMTIME StartTime; + DWORD_PTR Now; - GetLocalTime(&Time); + GetLocalTime(&StartTime); - Now = (DWORD_PTR)Time.wHour * 3600000 + - (DWORD_PTR)Time.wMinute * 60000; - if (pJob->JobTime > Now) - bToday = TRUE; + Now = (DWORD_PTR)StartTime.wHour * 3600000 + + (DWORD_PTR)StartTime.wMinute * 60000; - if (pJob->DaysOfMonth != 0) + StartTime.wMilliseconds = 0; + StartTime.wSecond = 0; + StartTime.wHour = (WORD)(pJob->JobTime / 3600000); + StartTime.wMinute = (WORD)((pJob->JobTime % 3600000) / 60000); + + /* 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) { - wDay = i; - break; + StartTime.wDay = 1; + StartTime.wMonth = 1; + StartTime.wYear++; + } + else + { + StartTime.wDay = 1; + StartTime.wMonth++; } } - ERR("Next day this month: %hu\n", wDay); + else + { + StartTime.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); } -#endif diff --git a/reactos/base/services/schedsvc/precomp.h b/reactos/base/services/schedsvc/precomp.h index d068608cc8f..0da85a0d450 100644 --- a/reactos/base/services/schedsvc/precomp.h +++ b/reactos/base/services/schedsvc/precomp.h @@ -28,7 +28,7 @@ typedef struct _JOB LIST_ENTRY JobEntry; LIST_ENTRY StartEntry; - LARGE_INTEGER StartTime; + FILETIME StartTime; WCHAR Name[9]; DWORD JobId; @@ -64,6 +64,9 @@ DeleteJob( LONG LoadJobs(VOID); +VOID +CalculateNextStartTime( + PJOB pJob); /* rpcserver.c */ diff --git a/reactos/base/services/schedsvc/rpcserver.c b/reactos/base/services/schedsvc/rpcserver.c index 8fc5cc821dc..e23371ec65a 100644 --- a/reactos/base/services/schedsvc/rpcserver.c +++ b/reactos/base/services/schedsvc/rpcserver.c @@ -121,11 +121,12 @@ NetrJobAdd( /* 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 start timer + // Update the start timer /* Return the new job ID */ *pJobId = pJob->JobId; @@ -162,9 +163,9 @@ NetrJobDel( if ((CurrentJob->JobId >= MinJobId) && (CurrentJob->JobId <= MaxJobId)) { - // Remove job from start list + // Remove job from the start list - // Update start timer + // Update the start timer /* Remove the job from the registry */ DeleteJob(CurrentJob);