diff options
| author | Igor Pashev <pashev.igor@gmail.com> | 2014-10-26 12:33:50 +0400 | 
|---|---|---|
| committer | Igor Pashev <pashev.igor@gmail.com> | 2014-10-26 12:33:50 +0400 | 
| commit | 47e6e7c84f008a53061e661f31ae96629bc694ef (patch) | |
| tree | 648a07f3b5b9d67ce19b0fd72e8caa1175c98f1a /qa/src/tztest.c | |
| download | pcp-debian.tar.gz | |
Debian 3.9.10debian/3.9.10debian
Diffstat (limited to 'qa/src/tztest.c')
| -rw-r--r-- | qa/src/tztest.c | 81 | 
1 files changed, 81 insertions, 0 deletions
| diff --git a/qa/src/tztest.c b/qa/src/tztest.c new file mode 100644 index 0000000..b5c6c2a --- /dev/null +++ b/qa/src/tztest.c @@ -0,0 +1,81 @@ +#include <stdio.h> +#include <time.h> +#include <stdlib.h> +#include <pcp/pmapi.h> +#include <pcp/impl.h> + +char * __pmTimezone(void); + +int main() +{ +    time_t sept = (30*365.25+244)*24*3600; /* 1 Septemnber 2000 */ +    time_t march = (30*365.25+60)*24*3600; /* 1 March 2000 */ + +    /* Two sets of timezone strings - one works for the first half +     * of the year, another for the second. Make sure that in the case +     * where we cannot reduce the timezone string and have to re-write it +     * same timezone is choosen */ +    char *zones[][8] = { +    { +	"ABC-10", +	"ABC-10:01:02XYZ-11:03:04,M12.5.0/3:04:05,M7.1.0/2:06:07", +	"ABC-10:00:00XYZ-11:00:00,M12.5.0/3:00:00,M7.5.0/2:00:00", +	"ABC-10XYZ-11,M12.5.0/3:00:00,M7.1.0/2:00:00", +	"ABC-10XYZ-11,M12.5.0/3:01:02,M7.1.0/2:03:04", +	"ABC-10", +	":Someplace/Somewhere", +	NULL +    }, +    { +	"ABC-10", +	"XYZ-11:03:04ABC-10:01:02,M12.5.0/3:04:05,M7.1.0/2:06:07", +	"ABC-10:00:00XYZ-11:00:00,M12.5.0/3:00:00,M7.5.0/2:00:00", +	"ABC-10XYZ-11,M12.5.0/3:00:00,M7.1.0/2:00:00", +	"XYZ-11ABC-10,M12.5.0/3:01:02,M7.1.0/2:03:04", +	"ABC-10", +	":Someplace/Somewhere", +	NULL +    }}; +    char * tz = getenv("TZ"); + +    if (tz == NULL) { +	puts("Timezone is not set, abort the test"); +    } else { +	int i; +	time_t now = time(NULL); +	struct tm * today = localtime(&now); +	int which = today->tm_mon / 6; +	char tb[256]; +	char * newtz = __pmTimezone(); + +	printf("%s -> %s\n", tz, newtz); + +	for (i=0; zones[which][i] != NULL; i++) { +	    char * tz; +	    struct tm  *tmp; +	    char tstr[64]; +	    int dst; + +	    sprintf(tb, "TZ=%s", zones[which][i]); +	    putenv(tb); +	    tzset(); +	    tz = getenv("TZ"); +            newtz = __pmTimezone(); + +            printf("%s -> %s\n", tz, newtz); +	    tmp = localtime(&march); +	    dst = tmp->tm_isdst; + +            strftime(tstr, 64, "%d %B %Y %H:%M %Z", tmp); +	    printf("In March daylight saving is %s, and the time is %s\n", +		(dst ? "on" : "off"), tstr); +	    tmp = localtime(&sept); +	    dst = tmp->tm_isdst; +            strftime(tstr, 64, "%d %B %Y %H:%M %Z", tmp); +	    printf("In September daylight saving is %s, and the time is %s\n\n", +		(dst ? "on" : "off"), tstr); +	} +    } +     +    return 0; +} | 
