[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [leafnode-list] [ANNOUNCE:] leafnode-1.9.12



Joerg Dietrich wrote:

> On Thu, Mar 30, 2000 at 09:34:06AM +0200, Cornelius Krasel wrote:
> > #ifdef HAVE_GMTOFF
> >     age = mktime( &timearray ) + (strstr( arg, "GMT" ) ? 0 : ltime->tm_gmtoff );
> > #else
> >     age = mktime( &timearray ) - (strstr( arg, "GMT" ) ? 0 : timezone);
> > #endif
> 
> Yes. At least west of GMT: timezone == -ltime->tm_gmtoff. Can some
> of you guys in Europe confirm this? I wonder why the old patch
> worked for Michael Schlensted (sp?). Any slrn user willing to
> test this?

I guess I am completely confused now. I tried the following example
program. It gets the time in seconds since the epoch into a structure
and converts it back into seconds since the epoch. Unfortunately, it
apparently doesn't work (i.e. it appears that time() returns seconds
since the epoch in "localtime" instead of UTC) or I got my brain in a
knot.

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

int main( void ) {
    time_t age;
    time_t now;
    struct tm * ltime;
    int year;
    int century;
    struct tm timearray;
    
    now = time( 0 );
    ltime = localtime( &now );
    year    = ltime->tm_year % 100;
    century = ltime->tm_year / 100;

    memset( &timearray, 0, sizeof(timearray) );
    timearray.tm_year = year + (century*100);
    timearray.tm_mon  = ltime->tm_mon;
    timearray.tm_mday = ltime->tm_mday;
    timearray.tm_hour = ltime->tm_hour;
    timearray.tm_min  = ltime->tm_min;
    timearray.tm_sec  = ltime->tm_sec;

    age = mktime( &timearray ) - ltime->tm_gmtoff;
    if ( ltime->tm_isdst ) {
	age = age - 3600;
    }

    printf("Old time  : %ld\n", now );
    printf("New time  : %ld\n", age );
    if ( ( now - age ) != 0 ) {
	printf("Difference: %ld\n", now-age );
    }
    printf("Offset: %ld\n", ltime->tm_gmtoff );

    exit(0);
}

Any clues?

--Cornelius.

-- 
/* Cornelius Krasel, U Wuerzburg, Dept. of Pharmacology, Versbacher Str. 9 */
/* D-97078 Wuerzburg, Germany   email: phak004@xxxxxxxxxxxxxxxxxxxxxx  SP4 */
/* "Science is the game we play with God to find out what His rules are."  */

-- 
leafnode-list@xxxxxxxxxxxxxxxxxxxxxxxxxxxx -- mailing list for leafnode
To unsubscribe, send mail with "unsubscribe" in the subject to the list