- Simplify the calculation in TIME_DaylightCompareDate;
- Expand the number of applicable test cases.
This commit is contained in:
parent
dd138e3176
commit
cfeef723d2
|
@ -273,7 +273,7 @@ void test_TzSpecificLocalTimeToSystemTime()
|
|||
fnSystemTimeToTzSpecificLocalTime pSystemTimeToTzSpecificLocalTime = NULL;
|
||||
TIME_ZONE_INFORMATION tzE, tzW, tzS;
|
||||
SYSTEMTIME result;
|
||||
int i;
|
||||
int i, j, year;
|
||||
pTzSpecificLocalTimeToSystemTime = (fnTzSpecificLocalTimeToSystemTime) GetProcAddress( hKernel, "TzSpecificLocalTimeToSystemTime");
|
||||
if(pTzSpecificLocalTimeToSystemTime)
|
||||
pSystemTimeToTzSpecificLocalTime = (fnTzSpecificLocalTimeToSystemTime) GetProcAddress( hKernel, "SystemTimeToTzSpecificLocalTime");
|
||||
|
@ -342,13 +342,44 @@ void test_TzSpecificLocalTimeToSystemTime()
|
|||
{ 18, &tzS, {2004,10,-1,24,2,0,0,0}, 5},
|
||||
{0}
|
||||
};
|
||||
/* days of transitions to put into the cases array */
|
||||
int yeardays[][6]=
|
||||
{
|
||||
{28,31,4,24,4,24} /* 1999 */
|
||||
, {26,29,2,22,2,22} /* 2000 */
|
||||
, {25,28,1,28,1,28} /* 2001 */
|
||||
, {31,27,7,27,7,27} /* 2002 */
|
||||
, {30,26,6,26,6,26} /* 2003 */
|
||||
, {28,31,4,24,4,24} /* 2004 */
|
||||
, {27,30,3,23,3,23} /* 2005 */
|
||||
, {26,29,2,22,2,22} /* 2006 */
|
||||
, {25,28,1,28,1,28} /* 2007 */
|
||||
, {30,26,6,26,6,26} /* 2008 */
|
||||
, {29,25,5,25,5,25} /* 2009 */
|
||||
, {28,31,4,24,4,24} /* 2010 */
|
||||
, {27,30,3,23,3,23} /* 2011 */
|
||||
, {25,28,1,28,1,28} /* 2012 */
|
||||
, {31,27,7,27,7,27} /* 2013 */
|
||||
, {30,26,6,26,6,26} /* 2014 */
|
||||
, {29,25,5,25,5,25} /* 2015 */
|
||||
, {27,30,3,23,3,23} /* 2016 */
|
||||
, {26,29,2,22,2,22} /* 2017 */
|
||||
, {25,28,1,28,1,28} /* 2018 */
|
||||
, {31,27,7,27,7,27} /* 2019 */
|
||||
,{0}
|
||||
};
|
||||
for( j=0 , year = 1999; yeardays[j][0] ; j++, year++) {
|
||||
for (i=0; cases[i].nr; i++) {
|
||||
if(i) cases[i].nr += 18;
|
||||
cases[i].slt.wYear = year;
|
||||
cases[i].slt.wDay = yeardays[j][i/3];
|
||||
pTzSpecificLocalTimeToSystemTime( cases[i].ptz, &(cases[i].slt), &result);
|
||||
ok( result.wHour == cases[i].ehour,
|
||||
"Test TzSpecificLocalTimeToSystemTime #%d. wrong system time. Hour is %d expected %d\n",
|
||||
cases[i].nr, result.wHour, cases[i].ehour);
|
||||
"Test TzSpecificLocalTimeToSystemTime #%d. Got %4d-%02d-%02d %02d:%02d. Expect hour = %02d\n",
|
||||
cases[i].nr, result.wYear, result.wMonth, result.wDay,
|
||||
result.wHour, result.wMinute, cases[i].ehour);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/* SystemTimeToTzSpecificLocalTime */
|
||||
{ TZLT2ST_case cases[] = {
|
||||
|
@ -377,11 +408,42 @@ void test_TzSpecificLocalTimeToSystemTime()
|
|||
|
||||
{0}
|
||||
};
|
||||
/* days of transitions to put into the cases array */
|
||||
int yeardays[][6]=
|
||||
{
|
||||
{27,30,4,24,4,24} /* 1999 */
|
||||
, {25,28,2,22,2,22} /* 2000 */
|
||||
, {24,27,1,28,1,28} /* 2001 */
|
||||
, {30,26,7,27,7,27} /* 2002 */
|
||||
, {29,25,6,26,6,26} /* 2003 */
|
||||
, {27,30,4,24,4,24} /* 2004 */
|
||||
, {26,29,3,23,3,23} /* 2005 */
|
||||
, {25,28,2,22,2,22} /* 2006 */
|
||||
, {24,27,1,28,1,28} /* 2007 */
|
||||
, {29,25,6,26,6,26} /* 2008 */
|
||||
, {28,24,5,25,5,25} /* 2009 */
|
||||
, {27,30,4,24,4,24} /* 2010 */
|
||||
, {26,29,3,23,3,23} /* 2011 */
|
||||
, {24,27,1,28,1,28} /* 2012 */
|
||||
, {30,26,7,27,7,27} /* 2013 */
|
||||
, {29,25,6,26,6,26} /* 2014 */
|
||||
, {28,24,5,25,5,25} /* 2015 */
|
||||
, {26,29,3,23,3,23} /* 2016 */
|
||||
, {25,28,2,22,2,22} /* 2017 */
|
||||
, {24,27,1,28,1,28} /* 2018 */
|
||||
, {30,26,7,27,7,27} /* 2019 */
|
||||
};
|
||||
for( j=0 , year = 1999; yeardays[j][0] ; j++, year++) {
|
||||
for (i=0; cases[i].nr; i++) {
|
||||
if(i) cases[i].nr += 18;
|
||||
cases[i].slt.wYear = year;
|
||||
cases[i].slt.wDay = yeardays[j][i/3];
|
||||
pSystemTimeToTzSpecificLocalTime( cases[i].ptz, &(cases[i].slt), &result);
|
||||
ok( result.wHour == cases[i].ehour,
|
||||
"Test SystemTimeToTzSpecificLocalTime #%d. wrong system time. Hour is %d expected %d\n",
|
||||
cases[i].nr, result.wHour, cases[i].ehour);
|
||||
"Test SystemTimeToTzSpecificLocalTime #%d. Got %4d-%02d-%02d %02d:%02d. Expect hour = %02d\n",
|
||||
cases[i].nr, result.wYear, result.wMonth, result.wDay,
|
||||
result.wHour, result.wMinute, cases[i].ehour);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -59,6 +59,18 @@ WINE_DEFAULT_DEBUG_CHANNEL(time);
|
|||
#define FILETIME2LL( pft, ll) \
|
||||
ll = (((LONGLONG)((pft)->dwHighDateTime))<<32) + (pft)-> dwLowDateTime ;
|
||||
|
||||
|
||||
static const int MonthLengths[2][12] =
|
||||
{
|
||||
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
|
||||
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
|
||||
};
|
||||
|
||||
static inline int IsLeapYear(int Year)
|
||||
{
|
||||
return Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* TIME_DayLightCompareDate
|
||||
*
|
||||
|
@ -86,61 +98,18 @@ static int TIME_DayLightCompareDate(
|
|||
|
||||
if (compareDate->wDayOfWeek <= 6)
|
||||
{
|
||||
SYSTEMTIME tmp;
|
||||
FILETIME tmp_ft;
|
||||
|
||||
WORD First;
|
||||
/* compareDate->wDay is interpreted as number of the week in the month
|
||||
* 5 means: the last week in the month */
|
||||
int weekofmonth = compareDate->wDay;
|
||||
|
||||
/* calculate day of week for the first day in the month */
|
||||
memcpy(&tmp, date, sizeof(SYSTEMTIME));
|
||||
tmp.wDay = 1;
|
||||
tmp.wDayOfWeek = -1;
|
||||
|
||||
if (weekofmonth == 5)
|
||||
{
|
||||
/* Go to the beginning of the next month. */
|
||||
if (++tmp.wMonth > 12)
|
||||
{
|
||||
tmp.wMonth = 1;
|
||||
++tmp.wYear;
|
||||
}
|
||||
}
|
||||
|
||||
if (!SystemTimeToFileTime(&tmp, &tmp_ft))
|
||||
return -2;
|
||||
|
||||
if (weekofmonth == 5)
|
||||
{
|
||||
LONGLONG t;
|
||||
FILETIME2LL( &tmp_ft, t)
|
||||
/* subtract one day */
|
||||
t -= (LONGLONG) 24*60*60*10000000;
|
||||
LL2FILETIME( t, &tmp_ft);
|
||||
}
|
||||
|
||||
if (!FileTimeToSystemTime(&tmp_ft, &tmp))
|
||||
return -2;
|
||||
|
||||
if (weekofmonth == 5)
|
||||
{
|
||||
/* calculate the last matching day of the week in this month */
|
||||
int dif = tmp.wDayOfWeek - compareDate->wDayOfWeek;
|
||||
if (dif < 0)
|
||||
dif += 7;
|
||||
|
||||
limit_day = tmp.wDay - dif;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* calculate the matching day of the week in the given week */
|
||||
int dif = compareDate->wDayOfWeek - tmp.wDayOfWeek;
|
||||
if (dif < 0)
|
||||
dif += 7;
|
||||
|
||||
limit_day = tmp.wDay + 7*(weekofmonth-1) + dif;
|
||||
}
|
||||
/* calculate the day of the first DayOfWeek in the month */
|
||||
First = ( 6 + compareDate->wDayOfWeek - date->wDayOfWeek + date->wDay
|
||||
) % 7 + 1;
|
||||
limit_day = First + 7 * (weekofmonth - 1);
|
||||
/* check needed for the 5th weekday of the month */
|
||||
if(limit_day > MonthLengths[date->wMonth==2 && IsLeapYear(date->wYear)]
|
||||
[date->wMonth - 1])
|
||||
limit_day -= 7;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue