📄 time.c
字号:
"Got Year %4d Month %2d Day %2d Hour %2d Min %2d Sec %2d mSec %3d\n",
st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond,
st.wMilliseconds);
ok(SetEnvironmentVariableA("TZ","GMT") != 0,
"SetEnvironmentVariableA failed\n");
ok(res != TIME_ZONE_ID_INVALID, "GetTimeZoneInformation failed\n");
ret = FileTimeToLocalFileTime(&ft, &lft);
ok( ret,
"FileTimeToLocalFileTime() failed with Error 0x%08lx\n",GetLastError());
FileTimeToSystemTime(&lft, &st);
ok(((st.wYear == 1970) && (st.wMonth == 1) && (st.wDay == 1) &&
(st.wHour == 0) && (st.wMinute == 0) && (st.wSecond == 1) &&
(st.wMilliseconds == 0)),
"Got Year %4d Month %2d Day %2d Hour %2d Min %2d Sec %2d mSec %3d\n",
st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond,
st.wMilliseconds);
ok(SetEnvironmentVariableA("TZ",NULL) != 0,
"SetEnvironmentVariableA failed\n");
}
/* test TzSpecificLocalTimeToSystemTime and SystemTimeToTzSpecificLocalTime
* these are in winXP and later */
typedef HANDLE (WINAPI *fnTzSpecificLocalTimeToSystemTime)( LPTIME_ZONE_INFORMATION, LPSYSTEMTIME, LPSYSTEMTIME);
typedef HANDLE (WINAPI *fnSystemTimeToTzSpecificLocalTime)( LPTIME_ZONE_INFORMATION, LPSYSTEMTIME, LPSYSTEMTIME);
typedef struct {
int nr; /* test case number for easier lookup */
TIME_ZONE_INFORMATION *ptz; /* ptr to timezone */
SYSTEMTIME slt; /* system/local time to convert */
WORD ehour; /* expected hour */
} TZLT2ST_case;
static void test_TzSpecificLocalTimeToSystemTime(void)
{
HMODULE hKernel = GetModuleHandle("kernel32");
fnTzSpecificLocalTimeToSystemTime pTzSpecificLocalTimeToSystemTime;
fnSystemTimeToTzSpecificLocalTime pSystemTimeToTzSpecificLocalTime = NULL;
TIME_ZONE_INFORMATION tzE, tzW, tzS;
SYSTEMTIME result;
int i, j, year;
pTzSpecificLocalTimeToSystemTime = (fnTzSpecificLocalTimeToSystemTime) GetProcAddress( hKernel, "TzSpecificLocalTimeToSystemTime");
if(pTzSpecificLocalTimeToSystemTime)
pSystemTimeToTzSpecificLocalTime = (fnTzSpecificLocalTimeToSystemTime) GetProcAddress( hKernel, "SystemTimeToTzSpecificLocalTime");
if( !pSystemTimeToTzSpecificLocalTime)
return;
ZeroMemory( &tzE, sizeof(tzE));
ZeroMemory( &tzW, sizeof(tzW));
ZeroMemory( &tzS, sizeof(tzS));
/* timezone Eastern hemisphere */
tzE.Bias=-600;
tzE.StandardBias=0;
tzE.DaylightBias=-60;
tzE.StandardDate.wMonth=10;
tzE.StandardDate.wDayOfWeek=0; /*sunday */
tzE.StandardDate.wDay=5; /* last (sunday) of the month */
tzE.StandardDate.wHour=3;
tzE.DaylightDate.wMonth=3;
tzE.DaylightDate.wDay=5;
tzE.DaylightDate.wHour=2;
/* timezone Western hemisphere */
tzW.Bias=240;
tzW.StandardBias=0;
tzW.DaylightBias=-60;
tzW.StandardDate.wMonth=10;
tzW.StandardDate.wDayOfWeek=0; /*sunday */
tzW.StandardDate.wDay=4; /* 4th (sunday) of the month */
tzW.StandardDate.wHour=2;
tzW.DaylightDate.wMonth=4;
tzW.DaylightDate.wDay=1;
tzW.DaylightDate.wHour=2;
/* timezone Eastern hemisphere */
tzS.Bias=240;
tzS.StandardBias=0;
tzS.DaylightBias=-60;
tzS.StandardDate.wMonth=4;
tzS.StandardDate.wDayOfWeek=0; /*sunday */
tzS.StandardDate.wDay=1; /* 1st (sunday) of the month */
tzS.StandardDate.wHour=2;
tzS.DaylightDate.wMonth=10;
tzS.DaylightDate.wDay=4;
tzS.DaylightDate.wHour=2;
/*tests*/
/* TzSpecificLocalTimeToSystemTime */
{ TZLT2ST_case cases[] = {
/* standard->daylight transition */
{ 1, &tzE, {2004,3,-1,28,1,0,0,0}, 15 },
{ 2, &tzE, {2004,3,-1,28,1,59,59,999}, 15},
{ 3, &tzE, {2004,3,-1,28,2,0,0,0}, 15},
/* daylight->standard transition */
{ 4, &tzE, {2004,10,-1,31,2,0,0,0} , 15 },
{ 5, &tzE, {2004,10,-1,31,2,59,59,999}, 15 },
{ 6, &tzE, {2004,10,-1,31,3,0,0,0}, 17 },
/* West and with fixed weekday of the month */
{ 7, &tzW, {2004,4,-1,4,1,0,0,0}, 5},
{ 8, &tzW, {2004,4,-1,4,1,59,59,999}, 5},
{ 9, &tzW, {2004,4,-1,4,2,0,0,0}, 5},
{ 10, &tzW, {2004,10,-1,24,1,0,0,0}, 4},
{ 11, &tzW, {2004,10,-1,24,1,59,59,999}, 4},
{ 12, &tzW, {2004,10,-1,24,2,0,0,0 }, 6},
/* and now south */
{ 13, &tzS, {2004,4,-1,4,1,0,0,0}, 4},
{ 14, &tzS, {2004,4,-1,4,1,59,59,999}, 4},
{ 15, &tzS, {2004,4,-1,4,2,0,0,0}, 6},
{ 16, &tzS, {2004,10,-1,24,1,0,0,0}, 5},
{ 17, &tzS, {2004,10,-1,24,1,59,59,999}, 5},
{ 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. 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[] = {
/* standard->daylight transition */
{ 1, &tzE, {2004,3,-1,27,15,0,0,0}, 1 },
{ 2, &tzE, {2004,3,-1,27,15,59,59,999}, 1},
{ 3, &tzE, {2004,3,-1,27,16,0,0,0}, 3},
/* daylight->standard transition */
{ 4, &tzE, {2004,10,-1,30,15,0,0,0}, 2 },
{ 5, &tzE, {2004,10,-1,30,15,59,59,999}, 2 },
{ 6, &tzE, {2004,10,-1,30,16,0,0,0}, 2 },
/* West and with fixed weekday of the month */
{ 7, &tzW, {2004,4,-1,4,5,0,0,0}, 1},
{ 8, &tzW, {2004,4,-1,4,5,59,59,999}, 1},
{ 9, &tzW, {2004,4,-1,4,6,0,0,0}, 3},
{ 10, &tzW, {2004,10,-1,24,4,0,0,0}, 1},
{ 11, &tzW, {2004,10,-1,24,4,59,59,999}, 1},
{ 12, &tzW, {2004,10,-1,24,5,0,0,0 }, 1},
/* and now south */
{ 13, &tzS, {2004,4,-1,4,4,0,0,0}, 1},
{ 14, &tzS, {2004,4,-1,4,4,59,59,999}, 1},
{ 15, &tzS, {2004,4,-1,4,5,0,0,0}, 1},
{ 16, &tzS, {2004,10,-1,24,5,0,0,0}, 1},
{ 17, &tzS, {2004,10,-1,24,5,59,59,999}, 1},
{ 18, &tzS, {2004,10,-1,24,6,0,0,0}, 3},
{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. 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);
}
}
}
}
START_TEST(time)
{
test_conversions();
test_invalid_arg();
test_GetTimeZoneInformation();
test_FileTimeToSystemTime();
test_FileTimeToLocalFileTime();
test_TzSpecificLocalTimeToSystemTime();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -