Hello all,
I have the following code that seems to be misbehaving depending on the timezone setting (TZ Environment variable). It gives the correct value when TZ is in POSIX format and the wrong value when in OLSON format.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <memory.h>
int main()
{
long secs;
char timeString[20];
struct tm timeHolder;
for(secs=0; secs < 3610; secs++)
{
localtime_r((const time_t *) &secs, (struct tm *) &timeHolder);
memset( timeString, 0, sizeof( timeString));
strftime( timeString, sizeof( timeString), "%H:%M:%S\0", &timeHolder);
printf("Secs: %d\t\t\tTime: %s\n", secs, timeString);
}
}
I compile and link this as follows:
gcc -o timeprob.exe timeprob.c
The run below is on AIX 6.1 (oslevel -r gives 6100-05). Same happens on Solaris 10.
date
Fri Apr 26 16:44:25 BST 2013
date -u
Fri Apr 26 15:44:38 GMT 2013
So currently we are 1 hour ahead of GMT with Daylight Savings in operation.
1] First with POSIX format TZ:
echo $TZ
GMT0BST,M3.5.0,M10.5.0
./timeprob.exe
<snip>
Secs: 3599 Time: 00:59:59
Secs: 3600 Time: 01:00:00
Secs: 3601 Time: 01:00:01
<snip>
ie. at 3600 secs from epoch the time shows correctly as 1 hour from epoch.
2] Next with OLSON format TZ:
echo $TZ
Europe/London
./timeprob.exe
<snip>
Secs: 3599 Time: 01:59:59
Secs: 3600 Time: 02:00:00
Secs: 3601 Time: 02:00:01
<snip>
ie. at 3600 secs from epoch the time shows wrongly as 2 hours from epoch.
- 'date' from Unix prompt shows the date correctly with/without DST.
- When there is no DST both format work correctly.
Any idea what the problem could be? I would expect both POSIX and OLSON formats should give the same output ie. either both should say 1 hour from epoch or both should say 2 hours from epoch.
The libc.a function used is that which comes with AIX 6.1.
Any help appreciated.
Regards