[PLUG] Question on mktime() results - not the unset TZ variable causing the problem

logical american website.reader3 at gmail.com
Wed Jan 27 06:58:51 UTC 2016


Steve:

Same result, so it's not the TZ environmental variable.

#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main() {

	char pacific_timezone[8] = "PST8PDT";
	char * timezone =&pacific_timezone[0];

	// Date: November 18, 1883 12:07:01 am PST

	struct tm first_tm;
	first_tm.tm_sec = 01;
	first_tm.tm_min = 07;
	first_tm.tm_hour = 12;
	first_tm.tm_mday = 18;
	first_tm.tm_mon = 10; // November
	first_tm.tm_year = -17; // 1883
	first_tm.tm_wday = 0; // Sunday
	first_tm.tm_yday = 321;
	first_tm.tm_isdst = 0;
	first_tm.tm_gmtoff = -28800;
	first_tm.tm_zone = timezone;

	// Date: November 18, 1883 12:07:02 am PST

	struct tm second_tm;
	second_tm.tm_sec = 02;
	second_tm.tm_min = 07;
	second_tm.tm_hour = 12;
	second_tm.tm_mday = 18;
	second_tm.tm_mon = 10; // November
	second_tm.tm_year = -17; // 1883
	second_tm.tm_wday = 0; // Sunday
	second_tm.tm_yday = 321;
	second_tm.tm_isdst = 0;
	second_tm.tm_gmtoff = -28800;
	second_tm.tm_zone = timezone;

	clearenv();
	const char* TZ = "TZ";
	const char* LA = "/usr/share/zoneinfo/America/Los_Angeles";
   	setenv(TZ,LA,1);
	char * gotit = getenv(TZ);
	printf( "TZ: %s\n",gotit);

	time_t first_time = mktime(&first_tm);
	time_t second_time = mktime(&second_tm);

	printf( "first struct tm object dump: %d %d %d %d %d %d %d %d %d %ld %s\n", first_tm.tm_sec, first_tm.tm_min, first_tm.tm_hour, first_tm.tm_mday, first_tm.tm_mon, first_tm.tm_year, first_tm.tm_wday, first_tm.tm_yday, first_tm.tm_isdst, first_tm.tm_gmtoff, first_tm.tm_zone);

	printf( "second struct tm object dump: %d %d %d %d %d %d %d %d %d %ld %s\n", second_tm.tm_sec, second_tm.tm_min, second_tm.tm_hour, second_tm.tm_mday, second_tm.tm_mon, second_tm.tm_year, second_tm.tm_wday, second_tm.tm_yday, second_tm.tm_isdst, second_tm.tm_gmtoff, second_tm.tm_zone);

	printf( "First time tick: %ld Second time tick: %ld Difference: %ld secs.  Should be -1 seconds instead.\n",first_time, second_time, first_time-second_time);

	printf( "Is this discrepancy due to the 7 min 2 sec difference between PST and Local Mean Time (Solar Time) ?\n");

	return (0);
}





-- 
CONFIDENTIAL: This email message and/or any attachments is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, copying, dissemination, disclosure, retention or distribution is strictly prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message along with any attachments. This communication (including attachments) is covered by the Electronic Communication Privacy Act, U.S.C. Sections 2510-2521.




More information about the PLUG mailing list