⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 y2k.c

📁 Netscape NSPR库源码
💻 C
📖 第 1 页 / 共 3 页
字号:
            PrintExplodedTime(&et_tmp);            printf("\n");        }        PR_ExplodeTime(prt[idx], PR_USPacificTimeParameters, &et_tmp);        if (!ExplodedTimeIsEqual(&et_tmp, &uspt[idx])) {            fprintf(stderr, "US Pacific Time not equal\n");            PrintExplodedTime(&et_tmp);            PrintExplodedTime(&uspt[idx]);            exit(1);        }        prt_tmp = PR_ImplodeTime(&et_tmp);        if (LL_NE(prt_tmp, prt[idx])) {            fprintf(stderr, "PRTime not equal\n");            exit(1);        }        if (debug_mode) {            printf("US Pacific Time: ");            PrintExplodedTime(&et_tmp);            printf("\n");        }        PR_ExplodeTime(prt[idx], PR_LocalTimeParameters, &et_tmp);        if (!ExplodedTimeIsEqual(&et_tmp, &localt[idx])) {            fprintf(stderr, "not equal\n");            PrintExplodedTime(&et_tmp);            PrintExplodedTime(&localt[idx]);            exit(1);        }        prt_tmp = PR_ImplodeTime(&et_tmp);        if (LL_NE(prt_tmp, prt[idx])) {            fprintf(stderr, "not equal\n");            exit(1);        }        if (debug_mode) {            printf("Local time:");            PrintExplodedTime(&et_tmp);            printf("\n\n");        }    }    now = PR_Now();    PR_ExplodeTime(now, PR_GMTParameters, &et_tmp);    printf("Current GMT is ");    PrintExplodedTime(&et_tmp);    printf("\n");    prt_tmp = PR_ImplodeTime(&et_tmp);    if (LL_NE(prt_tmp, now)) {        fprintf(stderr, "not equal\n");        exit(1);    }    PR_ExplodeTime(now, PR_USPacificTimeParameters, &et_tmp);    printf("Current US Pacific Time is ");    PrintExplodedTime(&et_tmp);    printf("\n");    prt_tmp = PR_ImplodeTime(&et_tmp);    if (LL_NE(prt_tmp, now)) {        fprintf(stderr, "not equal\n");        exit(1);    }    PR_ExplodeTime(now, PR_LocalTimeParameters, &et_tmp);    printf("Current local time is ");    PrintExplodedTime(&et_tmp);    printf("\n");    prt_tmp = PR_ImplodeTime(&et_tmp);    if (LL_NE(prt_tmp, now)) {        fprintf(stderr, "not equal\n");        exit(1);    }    printf("Please verify the results\n\n");    if (debug_mode) printf("Test 1 passed\n");    return PR_SUCCESS;}/* End of Test 1: TestExplodeImplodeTime *//* * Test 2: Normalize Time *//* * time increment for addition to PRExplodeTime */typedef struct time_increment {	PRInt32 ti_usec;	PRInt32 ti_sec;	PRInt32 ti_min;	PRInt32 ti_hour;} time_increment_t;/* * Data for testing PR_Normalize *		Add the increment to base_time, normalize it to GMT and US Pacific *		Time zone. */typedef struct normalize_test_data {    PRExplodedTime		base_time;     time_increment_t  	increment;    PRExplodedTime		expected_gmt_time;    PRExplodedTime		expected_uspt_time;} normalize_test_data_t;/* * Test data -	the base time values cover dates of interest including y2k - 1, *				y2k + 1, y2k leap year, y2k leap date + 1year, *				y2k leap date + 4 years */normalize_test_data_t normalize_test_array[] = {  /*usec sec min hour  mday  mo  year  wday yday {gmtoff, dstoff }*/	/* Fri 12/31/1999 19:32:48 PST */	{{0, 48, 32, 19, 31, 11, 1999, 5, 364, { -28800, 0}},    {0, 0, 30, 20},	{0, 48, 2, 0, 2, 0, 2000, 0, 1, { 0, 0}},	/*Sun Jan 2 00:02:48 UTC 2000*/	{0, 48, 2, 16, 1, 0, 2000, 6, 0, { -28800, 0}},/* Sat Jan 1 16:02:48														PST 2000*/	},	/* Fri 99-12-31 23:59:02 GMT */	{{0, 2, 59, 23, 31, 11, 1999, 5, 364, { 0, 0}},    {0, 0, 45, 0},	{0, 2, 44, 0, 1, 0, 2000, 6, 0, { 0, 0}},/* Sat Jan 1 00:44:02 UTC 2000*/	{0, 2, 44, 16, 31, 11, 1999, 5, 364, { -28800, 0}}/*Fri Dec 31 16:44:02														PST 1999*/	},	/* 99-12-25 12:00:00 GMT */	{{0, 0, 0, 12, 25, 11, 1999, 6, 358, { 0, 0}},    {0, 0, 0, 364 * 24},	{0, 0, 0, 12, 23, 11, 2000, 6, 357, { 0, 0}},/*Sat Dec 23 12:00:00													2000 UTC*/	{0, 0, 0, 4, 23, 11, 2000, 6, 357, { -28800, 0}}/*Sat Dec 23 04:00:00														2000 -0800*/	},	/* 00-01-1 00:00:00 PST */    {{0, 0, 0, 0, 1, 0, 2000, 6, 0, { -28800, 0}},    {0, 0, 0, 48},    {0, 0, 0, 8, 3, 0, 2000, 1, 2, { 0, 0}},/*Mon Jan  3 08:00:00 2000 UTC*/    {0, 0, 0, 0, 3, 0, 2000, 1, 2, { -28800, 0}}/*Mon Jan  3 00:00:00 2000																-0800*/	},	/* 00-01-10 12:00:00 PST */    {{0, 0, 0, 12, 10, 0, 2000, 1, 9, { -28800, 0}},    {0, 0, 0, 364 * 5 * 24},    {0, 0, 0, 20, 3, 0, 2005, 1, 2, { 0, 0}},/*Mon Jan  3 20:00:00 2005 UTC */    {0, 0, 0, 12, 3, 0, 2005, 1, 2, { -28800, 0}}/*Mon Jan  3 12:00:00														2005 -0800*/	},	/* 00-02-28 15:39 GMT */	{{0, 0, 39, 15, 28, 1, 2000, 1, 58, { 0, 0}},    {0,  0, 0, 24},	{0, 0, 39, 15, 29, 1, 2000, 2, 59, { 0, 0}}, /*Tue Feb 29 15:39:00 2000														UTC*/	{0, 0, 39, 7, 29, 1, 2000, 2, 59, { -28800, 0}}/*Tue Feb 29 07:39:00														2000 -0800*/	},	/* 01-03-01 12:00 PST */    {{0, 0, 0, 12, 3, 0, 2001, 3, 2, { -28800, 0}},/*Wed Jan 3 12:00:00													-0800 2001*/    {0, 30, 30,45},    {0, 30, 30, 17, 5, 0, 2001, 5, 4, { 0, 0}}, /*Fri Jan  5 17:30:30 2001													UTC*/    {0, 30, 30, 9, 5, 0, 2001, 5, 4, { -28800, 0}} /*Fri Jan  5 09:30:30														2001 -0800*/	},	/* 2004-04-26 12:00 GMT */	{{0, 0, 0, 20, 3, 0, 2001, 3, 2, { 0, 0}},    {0, 0, 30,0},	{0, 0, 30, 20, 3, 0, 2001, 3, 2, { 0, 0}},/*Wed Jan  3 20:30:00 2001 UTC*/     {0, 0, 30, 12, 3, 0, 2001, 3, 2, { -28800, 0}}/*Wed Jan  3 12:30:00														2001 -0800*/	},	/* 99-09-09 00:00 GMT */	{{0, 0, 0, 0, 9, 8, 1999, 4, 251, { 0, 0}},    {0, 0, 0, 12},    {0, 0, 0, 12, 9, 8, 1999, 4, 251, { 0, 0}},/*Thu Sep  9 12:00:00 1999 UTC*/    {0, 0, 0, 5, 9, 8, 1999, 4, 251, { -28800, 3600}}/*Thu Sep  9 05:00:00														1999 -0700*/	}};void add_time_increment(PRExplodedTime *et1, time_increment_t *it){	et1->tm_usec += it->ti_usec;	et1->tm_sec	+= it->ti_sec;	et1->tm_min += it->ti_min;	et1->tm_hour += it->ti_hour;}/*** TestNormalizeTime() -- Test PR_NormalizeTime()**		For each data item, add the time increment to the base_time and then**		normalize it for GMT and local time zones. This test assumes that**		the local time zone is the Pacific Time Zone. The normalized values**		should match the expected values in the data item.***/PRStatus TestNormalizeTime(void){int idx, count;normalize_test_data_t *itemp;time_increment_t *itp;	count = sizeof(normalize_test_array)/sizeof(normalize_test_array[0]);	for (idx = 0; idx < count; idx++) {		itemp = &normalize_test_array[idx];		if (debug_mode) {			printf("%2d. %15s",idx +1,"Base time: ");			PrintExplodedTime(&itemp->base_time);			printf("\n");		}		itp = &itemp->increment;		if (debug_mode) {			printf("%20s %2d hrs %2d min %3d sec\n","Add",itp->ti_hour,												itp->ti_min, itp->ti_sec);		}		add_time_increment(&itemp->base_time, &itemp->increment);		PR_NormalizeTime(&itemp->base_time, PR_LocalTimeParameters);		if (debug_mode) {			printf("%19s","PST time: ");			PrintExplodedTime(&itemp->base_time);			printf("\n");		}		if (!ExplodedTimeIsEqual(&itemp->base_time,									&itemp->expected_uspt_time)) {			printf("PR_NormalizeTime failed\n");			if (debug_mode)				PrintExplodedTime(&itemp->expected_uspt_time);			return PR_FAILURE;		}		PR_NormalizeTime(&itemp->base_time, PR_GMTParameters);		if (debug_mode) {			printf("%19s","GMT time: ");			PrintExplodedTime(&itemp->base_time);			printf("\n");		}		if (!ExplodedTimeIsEqual(&itemp->base_time,									&itemp->expected_gmt_time)) {			printf("PR_NormalizeTime failed\n");			return PR_FAILURE;		}	}	return PR_SUCCESS;}/*** ParseTest. Structure defining a string time and a matching exploded time***/typedef struct ParseTest{    char            *sDate;     /* string to be converted using PR_ParseTimeString() */    PRExplodedTime  et;         /* expected result of the conversion */} ParseTest;static ParseTest parseArray[] = {    /*                                  |<----- expected result ------------------------------------------->| */    /* "string to test"                   usec     sec min hour   day  mo  year  wday julian {gmtoff, dstoff }*/    { "Thursday 1 Jan 1970 00:00:00",   { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},    { "1 Jan 1970 00:00:00",            { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},    { "1-Jan-1970 00:00:00",            { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},    { "01-Jan-1970 00:00:00",           { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},    { "January 1, 1970",                { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},    { "January 1, 1970 00:00",          { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},    { "January 01, 1970 00:00",         { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},    { "January 01 1970 00:00",          { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},    { "January 01 1970 00:00:00",       { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},    { "01-01-1970",                     { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},    { "01/01/1970",                     { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},    { "01/01/70",                       { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},    { "01/01/70 00:00:00",              { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},    { "70/01/01 00:00:00",              { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},    { "70/1/1 00:00:",                  { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},    { "00:00 Thursday, January 1, 1970",{ 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},    { "1-Jan-70 00:00:00",              { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},    { "70-01-01 00:00:00",              { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},    { "70/01/01 00:00:00",              { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -