Improve converting speed in RtlTimeFieldsToTime/RtlTimeFieldsToTime.

Fixed an error if the month is negativ in RtlTimeFieldsToTime.

svn path=/trunk/; revision=3496
This commit is contained in:
Hartmut Birr 2002-09-13 18:58:36 +00:00
parent 61e3f21f42
commit 5d53de65e2

View file

@ -1,4 +1,4 @@
/* $Id: time.c,v 1.11 2002/09/08 10:23:42 chorns Exp $ /* $Id: time.c,v 1.12 2002/09/13 18:58:36 hbirr Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -112,6 +112,12 @@ RtlTimeToTimeFields (
/* compute year */ /* compute year */
CurYear = EPOCHYEAR; CurYear = EPOCHYEAR;
/* FIXME: handle calendar modifications */ /* FIXME: handle calendar modifications */
CurYear += Days / DAYSPERLEAPYEAR;
Days -= (CurYear - EPOCHYEAR) * DAYSPERLEAPYEAR;
CurYear--; /* The next calculation needs CurYear - 1 */
Days += CurYear - CurYear / 4 + CurYear / 100 - CurYear / 400;
CurYear++;
Days -= EPOCHYEAR - EPOCHYEAR / 4 + EPOCHYEAR / 100 - EPOCHYEAR / 400;
while (1) while (1)
{ {
LeapYear = IsLeapYear(CurYear); LeapYear = IsLeapYear(CurYear);
@ -139,54 +145,36 @@ RtlTimeFieldsToTime (
PLARGE_INTEGER Time PLARGE_INTEGER Time
) )
{ {
int CurYear, CurMonth, MonthLength; int CurMonth;
long long int rcTime; long long int rcTime;
TIME_FIELDS TimeFields = *tfTimeFields; TIME_FIELDS TimeFields = *tfTimeFields;
const int *Months;
rcTime = 0; rcTime = 0;
/* FIXME: normalize the TIME_FIELDS structure here */ /* Normalize the month value, because we don't know the length for month -1, 0, 13, 14, ... */
while (TimeFields.Second >= SECSPERMIN) if (TimeFields.Month < 1 || TimeFields.Month > 12)
{ {
NormalizeTimeFields(&TimeFields.Second, TimeFields.Year += (TimeFields.Month - 1) / MONSPERYEAR;
&TimeFields.Minute, TimeFields.Month = ((TimeFields.Month - 1) % MONSPERYEAR) + 1;
SECSPERMIN); if (TimeFields.Month < 1)
} {
while (TimeFields.Minute >= MINSPERHOUR) TimeFields.Year--;
{ TimeFields.Month += MONSPERYEAR;
NormalizeTimeFields(&TimeFields.Minute, }
&TimeFields.Hour, }
MINSPERHOUR); /* FIXME: handle calendar corrections here */
}
while (TimeFields.Hour >= HOURSPERDAY) rcTime += (TimeFields.Year - EPOCHYEAR) * DAYSPERNORMALYEAR;
{ /* Adjust leap years */
NormalizeTimeFields(&TimeFields.Hour, rcTime += (TimeFields.Year - 1)/ 4 - (TimeFields.Year - 1) / 100 + (TimeFields.Year - 1) / 400;
&TimeFields.Day, rcTime -= EPOCHYEAR / 4 - EPOCHYEAR / 100 + EPOCHYEAR / 400;
HOURSPERDAY);
}
MonthLength =
MonthLengths[IsLeapYear(TimeFields.Year)][TimeFields.Month - 1];
while (TimeFields.Day > MonthLength)
{
NormalizeTimeFields(&TimeFields.Day,
&TimeFields.Month,
MonthLength);
}
while (TimeFields.Month > MONSPERYEAR)
{
NormalizeTimeFields(&TimeFields.Month,
&TimeFields.Year,
MONSPERYEAR);
}
/* FIXME: handle calendar corrections here */ /* FIXME: handle calendar corrections here */
for (CurYear = EPOCHYEAR; CurYear < TimeFields.Year; CurYear++) Months = MonthLengths[IsLeapYear(TimeFields.Year)];
{
rcTime += YearLengths[IsLeapYear(CurYear)];
}
for (CurMonth = 1; CurMonth < TimeFields.Month; CurMonth++) for (CurMonth = 1; CurMonth < TimeFields.Month; CurMonth++)
{ {
rcTime += MonthLengths[IsLeapYear(CurYear)][CurMonth - 1]; rcTime += Months[CurMonth - 1];
} }
rcTime += TimeFields.Day - 1; rcTime += TimeFields.Day - 1;
rcTime *= SECSPERDAY; rcTime *= SECSPERDAY;