2038 year problem
Posted: 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
EDITED:
and this is what I get:
Is there any walkaround for that...?
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);
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