Originally posted by: DavidTopham
I have an issue with our software on an AIX 6.1.
Our software uses the mktime() call. We are seeing different behaviurs on two different AIX 6.1 installations, which are at different technology levels. Here is a code snippet that demonstrates the behaviour we are seeing:
struct tm tmTime;
time_t ttTime;
memset(&tmTime, 0, sizeof(tmTime));
// Set time to 1 Oct 2006
tmTime.tm_year = 106;
tmTime.tm_mon = 9;
tmTime.tm_mday = 1;
ttTime = mktime(&tmTime);
printf("TM1: %d %d %d %d %d %d %d %d %d\n", tmTime.tm_sec, tmTime.tm_min, tmTime.tm_hour,
tmTime.tm_mday, tmTime.tm_mon, tmTime.tm_year,
tmTime.tm_wday, tmTime.tm_yday, tmTime.tm_isdst);
printf("TT1: %d\n", ttTime);
printf("AT1: %s\n", asctime(&tmTime));
/* Add 2792 days*/
tmTime.tm_mday += 2792;
/* Call mktime again to normalise */
ttTime = mktime(&tmTime);
printf("TM2: %d %d %d %d %d %d %d %d %d\n", tmTime.tm_sec, tmTime.tm_min, tmTime.tm_hour,
tmTime.tm_mday, tmTime.tm_mon, tmTime.tm_year,
tmTime.tm_wday, tmTime.tm_yday, tmTime.tm_isdst);
printf("TT2: %d\n", ttTime);
printf("AT2: %s\n", asctime(&tmTime));
On AIX 6.1 TL1 (6100-01-01-0823), I get this output, which is what I expect to see:
TM1: 0 0 1 1 9 106 0 273 1
TT1: 1159682400
AT1: Sun Oct 1 01:00:00 2006
TM2: 0 0 1 24 4 114 6 143 1
TT2: 1400911200
AT2: Sat May 24 01:00:00 2014
In other words, adding 2792 days to the date, then calling mktime again to normalise it, has moved the time to 24 May 2014. (Note: whilst not everyone is familiar with it, the ability to add days (or whatever) to a tm structure then renormalise it with a call to mktime is expected and correct behaviour for the mktime function).
On AIX6.1 TL0 (6100-00-03-0808), however, I get this output:
TM1: 0 0 0 1 9 106 0 0 0
TT1: 1159678800
AT1: Sun Oct 1 00:00:00 2006
TM2: 0 0 0 2793 9 106 0 0 0
TT2: 1400907600
AT2: Sun Oct 93 00:00:00 2006
In other words, the second call to mktime has not normalised the tm structure as expected.
So it appears that there may have been an issue in TL 0 that was resolved in TL 1. However, I am struggling to confirm this, as I only have one box for each and cannot discount that something else could be the cause.
Did changes occur in AIX 6.1 between TL 0 and TL 1 that could account for this change in behaviour? Looking at the TL1 release notes on Fix Central, there are some fixes for mktime mentioned, but nothing exactly like this. If it was an issue in TL0 and it was fixed in TL1, that's fine, I can stipulate TL 1 as a minimum (yes, I realise TL0 and TL1 are both old and out of service now).
Thanks.
#AIX-Forum