I am doing a project and I need to be able to display a simple calendar for the month and year supplied by user input.
To do this I have written the following to determine the first day of the month selected.
My problem arises when I enter a year larger than 2038 and smaller than 1902. Reading through this forum I found out about the Year 2038 problem so I understand the upper limit but I cannot understand what the issue is with 1900 and 1901.Code:int getFirstDayOFMonth(unsigned year, unsigned month) { struct tm time_struct; time_struct.tm_year = year - 1900; time_struct.tm_mon = month - 1; time_struct.tm_mday = 1; time_struct.tm_sec = 0; time_struct.tm_min = 0; time_struct.tm_hour = 0; time_struct.tm_isdst = 0; if (mktime(&time_struct) == -1) return -1; else return time_struct.tm_wday; }
Is there any way to get around the 2038 problem for the case above?
Why is mktime() failing on the years 1900 and 1901? Is there a way around this?
Is there a way you can you go below 1900?