- Timestamp:
- 2010-06-03T11:00:45Z (14 years ago)
- Branches:
- master
- Children:
- a6b2f13
- Parents:
- 5f8ab6a9 (diff), f4bcc22 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/misc.c
r5f8ab6a9 r814aa52 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
r5f8ab6a9 r814aa52 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
Note: See TracChangeset
for help on using the changeset viewer.