mirror of
https://github.com/reactos/reactos.git
synced 2024-10-15 05:37:44 +00:00
Fixed SystemTimeToFileTime().
svn path=/trunk/; revision=479
This commit is contained in:
parent
7aaccee0e9
commit
0344d1a114
|
@ -30,19 +30,6 @@ typedef struct __DOSDATE
|
||||||
WORD Year:5;
|
WORD Year:5;
|
||||||
} DOSDATE, *PDOSDATE;
|
} DOSDATE, *PDOSDATE;
|
||||||
|
|
||||||
|
|
||||||
#define NSPERSEC 10000000
|
|
||||||
|
|
||||||
#define SECOND 1
|
|
||||||
#define MINUTE 60*SECOND
|
|
||||||
#define HOUR 60*MINUTE
|
|
||||||
#define DAY 24*HOUR
|
|
||||||
#define YEAR (365*DAY)
|
|
||||||
#define FOURYEAR (4*YEAR+DAY)
|
|
||||||
#define CENTURY (25*FOURYEAR-DAY)
|
|
||||||
#define MILLENIUM (100*CENTURY)
|
|
||||||
|
|
||||||
|
|
||||||
#define TICKSPERMIN 600000000
|
#define TICKSPERMIN 600000000
|
||||||
#define TICKSPERSEC 10000000
|
#define TICKSPERSEC 10000000
|
||||||
#define TICKSPERMSEC 10000
|
#define TICKSPERMSEC 10000
|
||||||
|
@ -70,12 +57,12 @@ static __inline int IsLeapYear(int Year)
|
||||||
return Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) ? 1 : 0;
|
return Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline void NormalizeTimeFields(CSHORT *FieldToNormalize,
|
static __inline void NormalizeTimeFields(WORD *FieldToNormalize,
|
||||||
CSHORT *CarryField,
|
WORD *CarryField,
|
||||||
int Modulus)
|
int Modulus)
|
||||||
{
|
{
|
||||||
*FieldToNormalize = (CSHORT) (*FieldToNormalize - Modulus);
|
*FieldToNormalize = (WORD) (*FieldToNormalize - Modulus);
|
||||||
*CarryField = (CSHORT) (*CarryField + 1);
|
*CarryField = (WORD) (*CarryField + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -180,71 +167,67 @@ SystemTimeToFileTime(
|
||||||
)
|
)
|
||||||
|
|
||||||
{
|
{
|
||||||
LARGE_INTEGER FileTime;
|
int CurYear, CurMonth, MonthLength;
|
||||||
LARGE_INTEGER Year;
|
long long int rcTime;
|
||||||
LARGE_INTEGER Month;
|
SYSTEMTIME SystemTime;
|
||||||
LARGE_INTEGER Day;
|
|
||||||
LARGE_INTEGER Hour;
|
|
||||||
LARGE_INTEGER Minute;
|
|
||||||
LARGE_INTEGER Second;
|
|
||||||
LARGE_INTEGER Milliseconds;
|
|
||||||
DWORD LeapDay = 0;
|
|
||||||
DWORD dwMonthDays = 0;
|
|
||||||
|
|
||||||
if ( (lpSystemTime->wYear % 4 == 0 && lpSystemTime->wYear % 100 != 0) || lpSystemTime->wYear % 400 == 0)
|
memcpy (&SystemTime, lpSystemTime, sizeof(SYSTEMTIME));
|
||||||
LeapDay = 1;
|
|
||||||
else
|
|
||||||
LeapDay = 0;
|
|
||||||
|
|
||||||
|
rcTime = 0;
|
||||||
|
|
||||||
Year = RtlEnlargedIntegerMultiply(lpSystemTime->wYear - 1601,YEAR);
|
/* FIXME: normalize the TIME_FIELDS structure here */
|
||||||
if ( lpSystemTime->wMonth > 1)
|
while (SystemTime.wSecond >= SECSPERMIN)
|
||||||
dwMonthDays = 31;
|
{
|
||||||
if ( lpSystemTime->wMonth > 2)
|
NormalizeTimeFields(&SystemTime.wSecond,
|
||||||
dwMonthDays += ( 28 + LeapDay );
|
&SystemTime.wMinute,
|
||||||
if ( lpSystemTime->wMonth > 3)
|
SECSPERMIN);
|
||||||
dwMonthDays += 31;
|
}
|
||||||
if ( lpSystemTime->wMonth > 4)
|
while (SystemTime.wMinute >= MINSPERHOUR)
|
||||||
dwMonthDays += 30;
|
{
|
||||||
if ( lpSystemTime->wMonth > 5)
|
NormalizeTimeFields(&SystemTime.wMinute,
|
||||||
dwMonthDays += 31;
|
&SystemTime.wHour,
|
||||||
if ( lpSystemTime->wMonth > 6)
|
MINSPERHOUR);
|
||||||
dwMonthDays += 30;
|
}
|
||||||
if ( lpSystemTime->wMonth > 7)
|
while (SystemTime.wHour >= HOURSPERDAY)
|
||||||
dwMonthDays += 31;
|
{
|
||||||
if ( lpSystemTime->wMonth > 8)
|
NormalizeTimeFields(&SystemTime.wHour,
|
||||||
dwMonthDays += 31;
|
&SystemTime.wDay,
|
||||||
if ( lpSystemTime->wMonth > 9)
|
HOURSPERDAY);
|
||||||
dwMonthDays += 30;
|
}
|
||||||
if ( lpSystemTime->wMonth > 10)
|
MonthLength =
|
||||||
dwMonthDays += 31;
|
MonthLengths[IsLeapYear(SystemTime.wYear)][SystemTime.wMonth - 1];
|
||||||
if ( lpSystemTime->wMonth > 11)
|
while (SystemTime.wDay > MonthLength)
|
||||||
dwMonthDays += 30;
|
{
|
||||||
|
NormalizeTimeFields(&SystemTime.wDay,
|
||||||
|
&SystemTime.wMonth,
|
||||||
|
MonthLength);
|
||||||
|
}
|
||||||
|
while (SystemTime.wMonth > MONSPERYEAR)
|
||||||
|
{
|
||||||
|
NormalizeTimeFields(&SystemTime.wMonth,
|
||||||
|
&SystemTime.wYear,
|
||||||
|
MONSPERYEAR);
|
||||||
|
}
|
||||||
|
|
||||||
Month = RtlEnlargedIntegerMultiply(dwMonthDays,DAY);
|
/* FIXME: handle calendar corrections here */
|
||||||
|
for (CurYear = EPOCHYEAR; CurYear < SystemTime.wYear; CurYear++)
|
||||||
|
{
|
||||||
|
rcTime += YearLengths[IsLeapYear(CurYear)];
|
||||||
|
}
|
||||||
|
for (CurMonth = 1; CurMonth < SystemTime.wMonth; CurMonth++)
|
||||||
|
{
|
||||||
|
rcTime += MonthLengths[IsLeapYear(CurYear)][CurMonth - 1];
|
||||||
|
}
|
||||||
|
rcTime += SystemTime.wDay - 1;
|
||||||
|
rcTime *= SECSPERDAY;
|
||||||
|
rcTime += SystemTime.wHour * SECSPERHOUR +
|
||||||
|
SystemTime.wMinute * SECSPERMIN + SystemTime.wSecond;
|
||||||
|
rcTime *= TICKSPERSEC;
|
||||||
|
rcTime += SystemTime.wMilliseconds * TICKSPERMSEC;
|
||||||
|
|
||||||
Day = RtlEnlargedIntegerMultiply(lpSystemTime->wDay,DAY);
|
*lpFileTime = *(FILETIME *)&rcTime;
|
||||||
|
|
||||||
Hour = RtlEnlargedIntegerMultiply(lpSystemTime->wHour,HOUR);
|
return TRUE;
|
||||||
Minute = RtlEnlargedIntegerMultiply(lpSystemTime->wMinute,MINUTE);
|
|
||||||
Second = RtlEnlargedIntegerMultiply(lpSystemTime->wSecond,DAY);
|
|
||||||
|
|
||||||
Milliseconds = RtlEnlargedIntegerMultiply(lpSystemTime->wMilliseconds,10000);
|
|
||||||
|
|
||||||
FileTime = RtlLargeIntegerAdd(FileTime,Year);
|
|
||||||
FileTime = RtlLargeIntegerAdd(FileTime,Month);
|
|
||||||
FileTime = RtlLargeIntegerAdd(FileTime,Day);
|
|
||||||
FileTime = RtlLargeIntegerAdd(FileTime,Hour);
|
|
||||||
FileTime = RtlLargeIntegerAdd(FileTime,Minute);
|
|
||||||
FileTime = RtlLargeIntegerAdd(FileTime,Second);
|
|
||||||
|
|
||||||
FileTime = RtlExtendedIntegerMultiply(FileTime,NSPERSEC);
|
|
||||||
|
|
||||||
FileTime = RtlLargeIntegerAdd(FileTime,Milliseconds);
|
|
||||||
|
|
||||||
memcpy(lpFileTime,&FileTime,sizeof(FILETIME));
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue