Problem
The OpenServer 5 mktime(S) function does not correctly normalize its input structure. For example, it does not correctly calculate going forward from the 24th of September to the 24th of October.
When going back 1 day from the start of a month, mktime subtracts 1 from tm_mon and adds 31 to tm_mday without taking into account the actual number of days in that particular month. This will only produce a correct result for those months that actually have 31 days.
This can be shown using the example below. If executed on SCO OpenServer 5.0.4, it produces:
0 883612800 Thu Jan 1 00:00:00 1998
0 886291200 Sun Feb 1 00:00:00 1998 <-- Correct - 31d
0 886204800 Sat Jan 31 00:00:00 19980 886291200 Sun Feb 1 00:00:00 1998
0 888710400 Sun Mar 1 00:00:00 1998 <-- Wrong - 28d
0 888883200 Tue Mar 3 00:00:00 19980 888710400 Sun Mar 1 00:00:00 1998
1 891385200 Wed Apr 1 00:00:00 1998 <-- Correct - 31d
1 891298800 Tue Mar 31 00:00:00 19981 891385200 Wed Apr 1 00:00:00 1998
1 893977200 Fri May 1 00:00:00 1998 <-- Wrong - 30d
1 893977200 Fri May 1 00:00:00 19981 893977200 Fri May 1 00:00:00 1998
1 896655600 Mon Jun 1 00:00:00 1998 <-- Correct - 31d
1 896569200 Sun May 31 00:00:00 19981 896655600 Mon Jun 1 00:00:00 1998
1 899247600 Wed Jul 1 00:00:00 1998 <-- Wrong - 30d
1 899247600 Wed Jul 1 00:00:00 1998etc.
...
...------------------------------------#include <time.h>
#include <stdio.h>/* * When going 1 day back from the start of a month, * mktime subtracts 1 from tm_mon and adds 31 to tm_mday * not considering the month it is going back to. */
int main(void) { struct tm when; time_t result; int month;
for (month = 1 - 1; month < 12; month++) {
/*
* First day in month
*/when.tm_isdst = -1; when.tm_year = 1998 - 1900; when.tm_mon = month; when.tm_mday = 1; when.tm_hour = 0; when.tm_min = 0; when.tm_sec = 0;
if ((result = mktime(&when)) != (time_t)-1) { printf("\n%d %d %s", when.tm_isdst, result, asctime(&when)); } else perror("mktime failed");
/*
* First day in next month
*/when.tm_mon++; when.tm_isdst = -1; if ((result = mktime(&when)) != (time_t)-1) { printf("%d %d %s", when.tm_isdst, result, asctime(&when)); } else perror("mktime failed");
/* * Go back 1 day to last day in month */
when.tm_mday--;when.tm_isdst = -1; if ((result = mktime(&when)) != (time_t)-1) { printf("%d %d %s", when.tm_isdst, result, asctime(&when)); } else perror("mktime failed"); }
return 0;
} Solution
This problem has been addressed with the following supplements:
SLS OSS603A for OpenServer 5.0.0SLS OSS601A for OpenServer 5.0.2 and 5.0.4Release Supplement 505A (rs505a) for OpenServer 5.0.5 See also
ta110166, "What is addressed by SLS OSS603A, the Year 2000 Supplement for SCO OpenServer 5.0.0 with rs500d and net100?"
ta110077, "What is addressed by SLS OSS601A, the Year 2000 Supplement for SCO OpenServer 5.0.2 and 5.0.4?".
ta109909, "What is Release Supplement 505A for SCO OpenServer Release 5.0.5?"
ta109280, "OpenServer 5.0.4 mktime(S) doesn't correctly handle the leap year in year 2000."
manual page: mktime(S)