I'm going through exercises from Advanced Programming in Unix and encountered the following question:
If the calendar time is stored as a signed 32-bit integer, in which year will it overflow?
positive signed integer = 2147483647
In the following calculation I'm not accounting for leap years:
((((2147483647 / 60sec) /60min)/24)/365) = 68.1yrs
This is a naive approach. How can I approach this question professionally?
The following solution presented earlier by a stack member was very helpful to print out the year.
int epoch_time = INT_MAX;
struct tm * timeinfo;
time_t epoch_time_as_time_t = epoch_time;
timeinfo = localtime(&epoch_time_as_time_t);
printf("2] overflow date: %s", asctime(timeinfo));