David Reid wrote:

AFAICT there's no way to
figure out how to set the gmt offset on Solaris when passing in a value,


After two minutes of manpage reading and one minute of coding:

   #include <time.h>
   #include <stdio.h>

   int main (void)
   {
       time_t t1, t2;
       struct tm tm;

       t1 = time(0);
       tm = *gmtime(&t1);
       t2 = mktime(&tm);

       printf("GMT offset = %ld\n", (long) difftime(t1, t2));
       return 0;
   }


All of this code uses only standard ANSI time functions. And the results:

   $ cc -o gmtoff gmtoff.c
   $ TZ=PST8PDT ./gmtoff
   GMT offset = -28800
   $ TZ=CET-1DST ./gmtoff
   GMT offset = 3600
   $ TZ=GMT ./gmtoff
   GMT offset = 0


That's on sparc-sun-solaris2.6, hppa1.1-hp-hpux10.20, and i686-pc-linux-gnu. I fail to see when this wouldn't work. Would this be a satisfactory solution on systems that don't have a tm_gmtoff field?


--
Brane Čibej
   home:   <[EMAIL PROTECTED]>             http://www.xbc.nu/brane/
   work:   <[EMAIL PROTECTED]>   http://www.hermes-softlab.com/
    ACM :   <[EMAIL PROTECTED]>            http://www.acm.org/





Reply via email to