2038 year problem

ikerbelloso
Posts: 20
Joined: Wed Jul 27, 2016 7:34 am

2038 year problem

Postby ikerbelloso » Thu Jun 01, 2017 11:51 am

Hi there,
I'm doing some test with sntp and date-time handling and I've found tha the newlib mktime and time functions suffer the 2038 effect problem.
I've done a little test for my system and there it is

Code: Select all

	struct tm tm_time;
	time_t epoch=0;
	struct timeval tv_time ;
	char strftime_buf[100];
	
	setenv("TZ", "UTC", 1);
	tzset();
	ESP_LOGI("test", "UTC timezone set");
	
	tm_time.tm_year		= 138;	//2038. 		years from 1900
	tm_time.tm_mon 		= 0; 		//January.	 0-11 month
	tm_time.tm_mday 		= 19;		//19th		1-31 day
	tm_time.tm_hour 		= 3; 		//3 am		0-23 hour
	tm_time.tm_min  		= 14; 	//13min		0-59 min
	tm_time.tm_sec  		=  0;
	tm_time.tm_yday 		= 19;
	tm_time.tm_wday		 = 1;

	strftime(strftime_buf, 100, "%c", &tm_time);
	ESP_LOGI("test", "The current local date/time UTC is: %s", strftime_buf);
	
	epoch=mktime(&tm_time);
	ESP_LOGI("test", "The epoch for that date is %d secs", (int)epoch);
	
	tv_time.tv_sec=epoch;
	tv_time.tv_usec=0;
	settimeofday(&tv_time,0);
	
	vTaskDelay(10000/portTICK_PERIOD_MS);
	
	time(&epoch);
	ESP_LOGE("test", "The epoch for that date is %d secs", (int)epoch);
	
	localtime_r(&epoch, &tm_time);
	strftime(strftime_buf, sizeof(strftime_buf), "%c", &tm_time);
	ESP_LOGE("test", "The current date/time UTC is: %s", strftime_buf);
	
	
EDITED:
and this is what I get:

Code: Select all

I (9753) test: The current date/time UTC is: Mon Jan 19 03:14:00 2038
I (9753) test: The epoch for that date is 2147483640 secs
E (19755) test: The epoch for that date is -2147483647 secs
E (19755) test: The current date/time UTC is: Fri Dec 13 20:45:53 1901
Is there any walkaround for that...?

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: 2038 year problem

Postby WiFive » Thu Jun 01, 2017 1:24 pm


Who is online

Users browsing this forum: YaCy [Bot] and 104 guests