mirror of
https://github.com/reactos/reactos.git
synced 2024-06-29 01:12:06 +00:00
[SCHEDSVC] Implement the job start time calculation for given days of month
This commit is contained in:
parent
d70c64bde0
commit
505b9f8052
|
@ -32,6 +32,8 @@ RTL_RESOURCE JobListLock;
|
||||||
LIST_ENTRY StartListHead;
|
LIST_ENTRY StartListHead;
|
||||||
RTL_RESOURCE StartListLock;
|
RTL_RESOURCE StartListLock;
|
||||||
|
|
||||||
|
static WORD wDaysArray[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||||
|
|
||||||
|
|
||||||
/* FUNCTIONS *****************************************************************/
|
/* FUNCTIONS *****************************************************************/
|
||||||
|
|
||||||
|
@ -449,13 +451,26 @@ done:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static
|
||||||
|
WORD
|
||||||
|
DaysOfMonth(
|
||||||
|
WORD wMonth,
|
||||||
|
WORD wYear)
|
||||||
|
{
|
||||||
|
if (wMonth == 2 && wYear % 4 == 0 && wYear % 400 != 0)
|
||||||
|
return 29;
|
||||||
|
|
||||||
|
return wDaysArray[wMonth];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
CalculateNextStartTime(
|
CalculateNextStartTime(
|
||||||
_In_ PJOB pJob)
|
_In_ PJOB pJob)
|
||||||
{
|
{
|
||||||
SYSTEMTIME CurrentSystemTime, StartSystemTime;
|
SYSTEMTIME CurrentSystemTime, StartSystemTime;
|
||||||
FILETIME StartFileTime;
|
FILETIME StartFileTime;
|
||||||
WORD wDaysOffset, wTempOffset, i, wJobDayOfWeek;
|
WORD wDaysOffset, wTempOffset, i, wJobDayOfWeek, wJobDayOfMonth;
|
||||||
DWORD_PTR CurrentTimeMs;
|
DWORD_PTR CurrentTimeMs;
|
||||||
BOOL bDaysOffsetValid;
|
BOOL bDaysOffsetValid;
|
||||||
|
|
||||||
|
@ -469,13 +484,6 @@ CalculateNextStartTime(
|
||||||
CurrentTimeMs = (DWORD_PTR)CurrentSystemTime.wHour * 3600000 +
|
CurrentTimeMs = (DWORD_PTR)CurrentSystemTime.wHour * 3600000 +
|
||||||
(DWORD_PTR)CurrentSystemTime.wMinute * 60000;
|
(DWORD_PTR)CurrentSystemTime.wMinute * 60000;
|
||||||
|
|
||||||
CopyMemory(&StartSystemTime, &CurrentSystemTime, sizeof(SYSTEMTIME));
|
|
||||||
|
|
||||||
StartSystemTime.wMilliseconds = 0;
|
|
||||||
StartSystemTime.wSecond = 0;
|
|
||||||
StartSystemTime.wHour = (WORD)(pJob->JobTime / 3600000);
|
|
||||||
StartSystemTime.wMinute = (WORD)((pJob->JobTime % 3600000) / 60000);
|
|
||||||
|
|
||||||
bDaysOffsetValid = FALSE;
|
bDaysOffsetValid = FALSE;
|
||||||
wDaysOffset = 0;
|
wDaysOffset = 0;
|
||||||
if ((pJob->DaysOfWeek == 0) && (pJob->DaysOfMonth == 0))
|
if ((pJob->DaysOfWeek == 0) && (pJob->DaysOfMonth == 0))
|
||||||
|
@ -497,7 +505,7 @@ CalculateNextStartTime(
|
||||||
{
|
{
|
||||||
if (pJob->DaysOfWeek & (1 << i))
|
if (pJob->DaysOfWeek & (1 << i))
|
||||||
{
|
{
|
||||||
/* Adjust the ranges */
|
/* Adjust the range */
|
||||||
wJobDayOfWeek = (i + 1) % 7;
|
wJobDayOfWeek = (i + 1) % 7;
|
||||||
TRACE("wJobDayOfWeek: %hu\n", wJobDayOfWeek);
|
TRACE("wJobDayOfWeek: %hu\n", wJobDayOfWeek);
|
||||||
TRACE("CurrentSystemTime.wDayOfWeek: %hu\n", CurrentSystemTime.wDayOfWeek);
|
TRACE("CurrentSystemTime.wDayOfWeek: %hu\n", CurrentSystemTime.wDayOfWeek);
|
||||||
|
@ -533,12 +541,55 @@ CalculateNextStartTime(
|
||||||
if (pJob->DaysOfMonth != 0)
|
if (pJob->DaysOfMonth != 0)
|
||||||
{
|
{
|
||||||
FIXME("Support DaysOfMonth!\n");
|
FIXME("Support DaysOfMonth!\n");
|
||||||
|
for (i = 0; i < 31; i++)
|
||||||
|
{
|
||||||
|
if (pJob->DaysOfMonth & (1 << i))
|
||||||
|
{
|
||||||
|
/* Adjust the range */
|
||||||
|
wJobDayOfMonth = i + 1;
|
||||||
|
FIXME("wJobDayOfMonth: %hu\n", wJobDayOfMonth);
|
||||||
|
FIXME("CurrentSystemTime.wDay: %hu\n", CurrentSystemTime.wDay);
|
||||||
|
|
||||||
|
if ((CurrentSystemTime.wDay > wJobDayOfMonth) ||
|
||||||
|
((CurrentSystemTime.wDay == wJobDayOfMonth) && (CurrentTimeMs >= pJob->JobTime)))
|
||||||
|
{
|
||||||
|
wTempOffset = DaysOfMonth(CurrentSystemTime.wMonth, CurrentSystemTime.wYear) -
|
||||||
|
CurrentSystemTime.wDay + wJobDayOfMonth;
|
||||||
|
FIXME("wTempOffset: %hu\n", wTempOffset);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wTempOffset = wJobDayOfMonth - CurrentSystemTime.wDay;
|
||||||
|
FIXME("wTempOffset: %hu\n", wTempOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Use the smallest offset */
|
||||||
|
if (bDaysOffsetValid == FALSE)
|
||||||
|
{
|
||||||
|
wDaysOffset = wTempOffset;
|
||||||
|
bDaysOffsetValid = TRUE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (wTempOffset < wDaysOffset)
|
||||||
|
wDaysOffset = wTempOffset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TRACE("wDaysOffset: %hu\n", wDaysOffset);
|
TRACE("wDaysOffset: %hu\n", wDaysOffset);
|
||||||
|
|
||||||
|
CopyMemory(&StartSystemTime, &CurrentSystemTime, sizeof(SYSTEMTIME));
|
||||||
|
|
||||||
|
StartSystemTime.wMilliseconds = 0;
|
||||||
|
StartSystemTime.wSecond = 0;
|
||||||
|
StartSystemTime.wHour = (WORD)(pJob->JobTime / 3600000);
|
||||||
|
StartSystemTime.wMinute = (WORD)((pJob->JobTime % 3600000) / 60000);
|
||||||
|
|
||||||
SystemTimeToFileTime(&StartSystemTime, &StartFileTime);
|
SystemTimeToFileTime(&StartSystemTime, &StartFileTime);
|
||||||
|
|
||||||
pJob->StartTime.u.LowPart = StartFileTime.dwLowDateTime;
|
pJob->StartTime.u.LowPart = StartFileTime.dwLowDateTime;
|
||||||
pJob->StartTime.u.HighPart = StartFileTime.dwHighDateTime;
|
pJob->StartTime.u.HighPart = StartFileTime.dwHighDateTime;
|
||||||
if (bDaysOffsetValid && wDaysOffset != 0)
|
if (bDaysOffsetValid && wDaysOffset != 0)
|
||||||
|
|
Loading…
Reference in a new issue