Changeset 2e3a857
- Timestamp:
- 2010-04-08T00:27:42Z (15 years ago)
- Branches:
- master
- Children:
- 08579a1
- Parents:
- 91cec2f
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/misc.c
r91cec2f r2e3a857 77 77 78 78 return mktime(&tm); 79 } 80 81 time_t mktime_utc( struct tm *tp ) 82 { 83 struct tm utc; 84 time_t res, tres; 85 86 tp->tm_isdst = -1; 87 res = mktime( tp ); 88 /* Problem is, mktime() just gave us the GMT timestamp for the 89 given local time... While the given time WAS NOT local. So 90 we should fix this now. 91 92 Now I could choose between messing with environment variables 93 (kludgy) or using timegm() (not portable)... Or doing the 94 following, which I actually prefer... 95 96 tzset() may also work but in other places I actually want to 97 use local time. 98 99 FFFFFFFFFFFFFFFFFFFFFUUUUUUUUUUUUUUUUUUUU!! */ 100 gmtime_r( &res, &utc ); 101 utc.tm_isdst = -1; 102 if( utc.tm_hour == tp->tm_hour && utc.tm_min == tp->tm_min ) 103 /* Sweet! We're in UTC right now... */ 104 return res; 105 106 tres = mktime( &utc ); 107 res += res - tres; 108 109 /* Yes, this is a hack. And it will go wrong around DST changes. 110 BUT this is more likely to be threadsafe than messing with 111 environment variables, and possibly more portable... */ 112 113 return res; 79 114 } 80 115 -
lib/misc.h
r91cec2f r2e3a857 43 43 44 44 G_MODULE_EXPORT time_t get_time( int year, int month, int day, int hour, int min, int sec ); 45 G_MODULE_EXPORT time_t mktime_utc( struct tm *tp ); 45 46 double gettime( void ); 46 47 -
protocols/jabber/jabber_util.c
r91cec2f r2e3a857 667 667 time_t jabber_get_timestamp( struct xt_node *xt ) 668 668 { 669 struct tm tp, utc;670 669 struct xt_node *c; 671 time_t res, tres;672 670 char *s = NULL; 671 struct tm tp; 673 672 674 673 for( c = xt->children; ( c = xt_find_node( c, "x" ) ); c = c->next ) … … 688 687 tp.tm_year -= 1900; 689 688 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 ); 714 691 } 715 692
Note: See TracChangeset
for help on using the changeset viewer.