TIme zones revisited
F.A.Akeroyd at rl.ac.uk
F.A.Akeroyd at rl.ac.uk
Tue Mar 14 11:59:31 GMT 2000
Ray,
Both "gmtime" and "localtime" return pointers to "static" data and so if you
called "gmtime" twice with a different time argument, it would be expected
to
change the results of a previous call. From what you have said, it would
appear that your system has gmtime() and localtime() implemented together
using
the same storage; you can check this by using
printf("%p\n", (void*)value_from_localtime_or_gmtime);
To see if they are pointing at the same memory location. I'd say the
behaviour
was slightly odd, but not unimaginable. The solution would be to either (1)
make a copy of the result before calling another function or (2) use
"reentrant"
versions e.g. localtime_r(), gmtime_r()
Regarding the change to timezone calculation, i was not sure whether
we should be using
gmt_offset = difftime(mktime(localtime(&timer)),
mktime(gmtime(&timer)));
Is "mktime(localtime(&timer))" always the same as "timer"? Some help
pages i see say that "timer" is related to "Coordinated Universal Time"
and so might it have daylight/timezone information hidden in it?
Freddie
--
Freddie Akeroyd Tel: (01235) 445457
ISIS Facility Fax: (01235) 445720
Rutherford Appleton Laboratory
Chilton, DIDCOT, OX11 OQX, GB http://www.isis.rl.ac.uk/
-----Original Message-----
From: Ray Osborn [mailto:ROsborn at anl.gov]
Sent: 13 March 2000 20:31
To: NeXus
Subject: TIme zones revisited
Eric says that the modifications suggested in my last post worked OK.
However, I discovered a strange side effect when using gcc on Linux. It
appears that running "gmtime" then changes the value of the tm struct
earlier set by "localtime" i.e. the hour is set to the GMT hour. This seems
to be a "feature" of gcc. It doesn't happen with other compilers I've used.
What this means is that you may have to add a second call to localtime after
calculating gmt_offset. If you edit napi.c, use :
#else
gmt_offset = difftime (timer, mktime(gmtime(&timer)));
time_info = localtime (&timer);
#endif
Following this message is a simple program to decide if your compiler has
strange behaviour.
The problem is not particularly serious. It just means that you will have
the wrong file creation time. We will try and sort this out before the next
release of the API.
Ray Osborn
--
Dr Ray Osborn Tel: +1 (630) 252-9011
Materials Science Division Fax: +1 (630) 252-7777
Argonne National Laboratory E-mail: ROsborn at anl.gov
Argonne, IL 60439-4845
--
#include <time.h>
#include <stdio.h>
main ()
{
time_t timer;
struct tm *time_info, *gmt_info;
time(&timer);
time_info = localtime(&timer);
printf ("After calling localtime, the local hour is %d\n",
time_info->tm_hour);
gmt_info = gmtime(&timer);
printf ("After calling gmtime, the GMT hour is %d\n",
gmt_info->tm_hour);
printf ("After calling gmtime, the local hour is %d\n",
time_info->tm_hour);
time_info = localtime(&timer);
printf ("Ater calling localtime again, the local hour is %d\n",
time_info->tm_hour);
}
More information about the NeXus-developers
mailing list