From: Dave H. <hel...@us...> - 2013-02-20 16:30:01
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "sfcb - Small Footprint CIM Broker". The branch, master has been updated via 840ee3df1dce230cfd03d7d171946d26f456a31f (commit) from 72f7aae5e0a1a5935f1015bbb14dca46df0e6637 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 840ee3df1dce230cfd03d7d171946d26f456a31f Author: Dave Heller <hel...@us...> Date: Wed Feb 20 11:28:11 2013 -0500 [2552] datetime conversions do not handle timezone ----------------------------------------------------------------------- Summary of changes: NEWS | 1 + datetime.c | 9 ++-- test/unittest/newDateTime.c | 112 +++++++++++++++++++++++++++++++++++++++--- 3 files changed, 109 insertions(+), 13 deletions(-) diff --git a/NEWS b/NEWS index 3782ea7..fa598bd 100644 --- a/NEWS +++ b/NEWS @@ -28,6 +28,7 @@ Bugs fixed: - 3603454 control should do type conversions on startup - 2612 Don't persist indications - 2613 Check sfcCommon version +- 2552 datetime conversions do not handle timezone Changes in 1.4.3 ================ diff --git a/datetime.c b/datetime.c index 92a8c2b..cdbae38 100644 --- a/datetime.c +++ b/datetime.c @@ -2,7 +2,7 @@ /* * datetime.c * - * (C) Copyright IBM Corp. 2005 + * (C) Copyright IBM Corp. 2013 * * THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE @@ -135,24 +135,23 @@ chars2bin(const char *string, CMPIStatus *rc) else { struct tm tmp; + time_t sse; memset(&tmp, 0, sizeof(struct tm)); tzset(); - tmp.tm_gmtoff = timezone; - tmp.tm_isdst = daylight; tmp.tm_mday = atoi(str + 6); str[6] = 0; tmp.tm_mon = atoi(str + 4) - 1; str[4] = 0; tmp.tm_year = atoi(str) - 1900; - if(mktime(&tmp) < 0) { + if((sse = timegm(&tmp)) < 0) { CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER); } msecs = msecs + (secs * 1000000ULL); - msecs += (CMPIUint64) mktime(&tmp) * 1000000ULL; + msecs += (CMPIUint64) sse * 1000000ULL; // Add in the offset msecs -= offset * 1000000ULL; } diff --git a/test/unittest/newDateTime.c b/test/unittest/newDateTime.c index daa5e0d..621514d 100644 --- a/test/unittest/newDateTime.c +++ b/test/unittest/newDateTime.c @@ -2,6 +2,7 @@ #include <stdio.h> #include <stdlib.h> #define TRUE 1 +#define FALSE 0 #define CMPI_PLATFORM_LINUX_GENERIC_GNU @@ -15,9 +16,16 @@ #define SFCB_ASM(x) #endif +extern CMPIDateTime *NewCMPIDateTime(CMPIStatus *rc); +extern CMPIDateTime *NewCMPIDateTimeFromBinary(CMPIUint64 binTime, + CMPIBoolean interval, CMPIStatus *rc); +extern CMPIDateTime *NewCMPIDateTimeFromChars(const char *utcTime, + CMPIStatus *rc); + CMPIDateTime *dt, *dt1, - *dt2; + *dt2, + *dt3; CMPIStatus st, st1, st2, @@ -28,19 +36,107 @@ main(void) { int rc = 0; const char *str = "00000024163645.123456:000"; + char *current, *result; + long long blob; + printf("Performing NewDateTime tests.... \n"); + printf("- Getting current time from NewCMPIDateTime()...\n"); dt = (CMPIDateTime *) NewCMPIDateTime(&st); - printf("Done dt \n"); - dt1 = - (CMPIDateTime *) NewCMPIDateTimeFromBinary((CMPIUint64) 1000000, - TRUE, &st1); - printf("Done dt1 \n"); + printf(" Current time in CMPIDateTime: %s\n", + current = (char*) dt->ft->getStringFormat(dt, NULL )->hdl); + printf(" Current time in usec since 1970-01-01: %ld\n", + blob = (long long) dt->ft->getBinaryFormat(dt, NULL )); + printf( + "- Converting back to CMPIDateTime using NewCMPIDateTimeFromBinary()...\n"); + dt = (CMPIDateTime *) NewCMPIDateTimeFromBinary((CMPIUint64) blob, FALSE, + &st1); + printf(" Convert time in CMPIDateTime: %s\n", + result = (char*) dt->ft->getStringFormat(dt, NULL )->hdl); + if (!strcmp(current, result)) + printf(" Result matches the original string.\n"); + else { + printf(" Result does not match the original string.\n"); + rc = 1; + } + + printf("Performing interval tests....\n"); + printf("- Getting a 1s interval from NewCMPIDateTime()...\n"); + blob = (CMPIUint64) 1000000; + dt1 = (CMPIDateTime *) NewCMPIDateTimeFromBinary(blob, TRUE, &st1); + printf(" Interval in CMPIDateTime: %s\n", + result = (char*) dt1->ft->getStringFormat(dt1, NULL )->hdl); + + printf("- Getting a test interval from NewCMPIDateTime()...\n"); dt2 = (CMPIDateTime *) NewCMPIDateTimeFromChars(str, &st2); - printf("Done dt2 \n"); + printf(" Interval in CMPIDateTime: %s\n", + result = (char*) dt2->ft->getStringFormat(dt2, NULL )->hdl); + + printf("Performing NewCMPIDateTimeFromChars() tests....\n"); + printf("- Creating a test date in standard time...\n"); + char cimDt[26]; + char buffr[11]; + long usecs = 0L; + struct tm bdt; + + memset(&bdt, 0, sizeof(struct tm)); + bdt.tm_isdst = -1; + bdt.tm_year = 2015 - 1900; + bdt.tm_mon = 2 - 1; + bdt.tm_mday = 19; + + mktime(&bdt); // get value of tm_gmtoff + + strftime(cimDt, 26, "%Y%m%d%H%M%S.", &bdt); + snprintf(buffr, 11, "%6.6ld%+4.3ld", usecs, bdt.tm_gmtoff / 60); + strcat(cimDt, buffr); + str = cimDt; + dt3 = (CMPIDateTime *) NewCMPIDateTimeFromChars(str, &st3); + printf(" Test date in CMPIDateTime: %s\n", + (char*) dt3->ft->getStringFormat(dt3, NULL )->hdl); + printf(" Test date in usec since 1970-01-01: %ld\n", + blob = (long long) dt3->ft->getBinaryFormat(dt3, NULL )); + printf( + "- Converting back to CMPIDateTime using NewCMPIDateTimeFromBinary()...\n"); + dt3 = (CMPIDateTime *) NewCMPIDateTimeFromBinary((CMPIUint64) blob, FALSE, + &st1); + printf(" Convert time in CMPIDateTime: %s\n", + result = (char*) dt3->ft->getStringFormat(dt3, NULL )->hdl); + if (!strcmp(str, result)) + printf(" Result matches the original string.\n"); + else { + printf(" Result does not match the original string.\n"); + rc = 1; + } + + printf("- Creating a test date in daylight saving time...\n"); + bdt.tm_mon = 8 - 1; + mktime(&bdt); + strftime(cimDt, 26, "%Y%m%d%H%M%S.", &bdt); + snprintf(buffr, 11, "%6.6ld%+4.3ld", usecs, bdt.tm_gmtoff / 60); + strcat(cimDt, buffr); + str = cimDt; + dt3 = (CMPIDateTime *) NewCMPIDateTimeFromChars(str, &st3); + printf(" Test date in CMPIDateTime: %s\n", + (char*) dt3->ft->getStringFormat(dt3, NULL )->hdl); + printf(" Test date in usec since 1970-01-01: %ld\n", + blob = (long long) dt3->ft->getBinaryFormat(dt3, NULL )); + printf( + "- Converting back to CMPIDateTime using NewCMPIDateTimeFromBinary()...\n"); + dt3 = (CMPIDateTime *) NewCMPIDateTimeFromBinary((CMPIUint64) blob, FALSE, + &st1); + printf(" Convert time in CMPIDateTime: %s\n", + result = (char*) dt3->ft->getStringFormat(dt3, NULL )->hdl); + if (!strcmp(str, result)) + printf(" Result matches the original string.\n"); + else { + printf(" Result does not match the original string.\n"); + rc = 1; + } + printf("st.rc = %d \n ", st.rc); printf("st1.rc = %d \n ", st1.rc); printf("st2.rc = %d \n ", st2.rc); - if (CMIsInterval((const CMPIDateTime *) dt2, &st3.rc)) + if (CMIsInterval((const CMPIDateTime *) dt2, &st2)) printf("dt2 is Interval... \n"); if (st.rc != CMPI_RC_OK) { hooks/post-receive -- sfcb - Small Footprint CIM Broker |