TIme zones revisited

Ray Osborn ROsborn at anl.gov
Mon Mar 13 19:30:38 GMT 2000


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 mailing list