Changeset 2e3a857 for protocols


Ignore:
Timestamp:
2010-04-08T00:27:42Z (15 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
08579a1
Parents:
91cec2f
Message:

Added a mktime_utc() to misc.c using code that used to be in jabber_util.c.
I want to use this in the Twitter module.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/jabber_util.c

    r91cec2f r2e3a857  
    667667time_t jabber_get_timestamp( struct xt_node *xt )
    668668{
    669         struct tm tp, utc;
    670669        struct xt_node *c;
    671         time_t res, tres;
    672670        char *s = NULL;
     671        struct tm tp;
    673672       
    674673        for( c = xt->children; ( c = xt_find_node( c, "x" ) ); c = c->next )
     
    688687        tp.tm_year -= 1900;
    689688        tp.tm_mon --;
    690         tp.tm_isdst = -1; /* GRRRRRRRRRRR */
    691        
    692         res = mktime( &tp );
    693         /* Problem is, mktime() just gave us the GMT timestamp for the
    694            given local time... While the given time WAS NOT local. So
    695            we should fix this now.
    696        
    697            Now I could choose between messing with environment variables
    698            (kludgy) or using timegm() (not portable)... Or doing the
    699            following, which I actually prefer... */
    700         gmtime_r( &res, &utc );
    701         utc.tm_isdst = -1; /* Once more: GRRRRRRRRRRRRRRRRRR!!! */
    702         if( utc.tm_hour == tp.tm_hour && utc.tm_min == tp.tm_min )
    703                 /* Sweet! We're in UTC right now... */
    704                 return res;
    705        
    706         tres = mktime( &utc );
    707         res += res - tres;
    708        
    709         /* Yes, this is a hack. And it will go wrong around DST changes.
    710            BUT this is more likely to be threadsafe than messing with
    711            environment variables, and possibly more portable... */
    712        
    713         return res;
     689       
     690        return mktime_utc( &tp );
    714691}
    715692
Note: See TracChangeset for help on using the changeset viewer.