If you dig through the typedefs in the source code for ESP32, you'll see that 'time_t' is indeed defined as a 'long' (aka int32_t). So, it's Posix time() function will roll over at UTC: Tuesday, January 19 2038 03:14:07. Immediately after roll over, the time will be UTC: Friday, December 13 1901 20:45:52:
void printTimeInfo (time_t epchoTime);
void setup() {
time_t timeVal;
Serial.begin(115200);
delay(2000);
timeVal = 1704373697;
printTimeInfo(timeVal);
Serial.printf("\n");
timeVal = 0;
printTimeInfo(timeVal);
Serial.printf("\n");
timeVal--;
printTimeInfo(timeVal);
Serial.printf("\n");
timeVal = 0x7FFFFFFF;
printTimeInfo(timeVal);
Serial.printf("\n");
timeVal++;
printTimeInfo(timeVal);
Serial.printf("\n");
}
void printTimeInfo (time_t epchoTime) {
char timeString[100];
tm *timeinfo;
Serial.printf("Epcho Time = 0x%08X\n", static_cast<uint32_t> (epchoTime));
timeinfo = gmtime(&epchoTime);
strftime(timeString, 100, "UTC: %A, %B %d %Y %H:%M:%S %Z", timeinfo);
Serial.printf("%s\n", timeString);
Serial.printf("tm Struture Values:\n");
Serial.printf("Year = %d, Mon = %d, Day = %d\n", timeinfo->tm_year, timeinfo->tm_mon, timeinfo->tm_mday);
Serial.printf("Hour = %d, Min = %d, Sec = %d\n", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
Serial.printf("DoY = %d, DoW = %d, IsDST = %d\n", timeinfo->tm_yday, timeinfo->tm_wday, timeinfo->tm_isdst);
}
void loop() {
}
Epcho Time = 0x6596ADC1
UTC: Thursday, January 04 2024 13:08:17 GMT
tm Struture Values:
Year = 124, Mon = 0, Day = 4
Hour = 13, Min = 8, Sec = 17
DoY = 3, DoW = 4, IsDST = 0
Epcho Time = 0x00000000
UTC: Thursday, January 01 1970 00:00:00 GMT
tm Struture Values:
Year = 70, Mon = 0, Day = 1
Hour = 0, Min = 0, Sec = 0
DoY = 0, DoW = 4, IsDST = 0
Epcho Time = 0xFFFFFFFF
UTC: Wednesday, December 31 1969 23:59:59 GMT
tm Struture Values:
Year = 69, Mon = 11, Day = 31
Hour = 23, Min = 59, Sec = 59
DoY = 364, DoW = 3, IsDST = 0
Epcho Time = 0x7FFFFFFF
UTC: Tuesday, January 19 2038 03:14:07 GMT
tm Struture Values:
Year = 138, Mon = 0, Day = 19
Hour = 3, Min = 14, Sec = 7
DoY = 18, DoW = 2, IsDST = 0
Epcho Time = 0x80000000
UTC: Friday, December 13 1901 20:45:52 GMT
tm Struture Values:
Year = 1, Mon = 11, Day = 13
Hour = 20, Min = 45, Sec = 52
DoY = 346, DoW = 5, IsDST = 0