apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Branko ─îibej <br...@xbc.nu>
Subject Re: apr_implode_time and time zones
Date Thu, 28 Jun 2001 22:47:32 GMT
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:   <brane@xbc.nu>             http://www.xbc.nu/brane/
    work:   <branko.cibej@hermes.si>   http://www.hermes-softlab.com/
     ACM :   <brane@acm.org>            http://www.acm.org/

View raw message