Fix offsetting local time back to UTC.
This commit is contained in:
		@@ -35,8 +35,7 @@ char *mpw_get_token(const char **in, const char *eol, char *delim) {
 | 
			
		||||
    return token;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
time_t mpw_timegm(
 | 
			
		||||
        const char *time) {
 | 
			
		||||
time_t mpw_timegm(const char *time) {
 | 
			
		||||
 | 
			
		||||
    // TODO: Support for parsing non-UTC time strings
 | 
			
		||||
    // Parse time as a UTC timestamp, into a tm.
 | 
			
		||||
@@ -49,7 +48,8 @@ time_t mpw_timegm(
 | 
			
		||||
 | 
			
		||||
        // mktime interprets tm as being local, we need to offset back to UTC (timegm/tm_gmtoff are non-standard).
 | 
			
		||||
        time_t local_time = mktime( &tm ), local_dst = tm.tm_isdst > 0? 3600: 0;
 | 
			
		||||
        return local_time + local_dst - mktime( gmtime( &local_time ) );
 | 
			
		||||
        time_t gmtoff = local_time + local_dst - mktime( gmtime( &local_time ) );
 | 
			
		||||
        return local_time + gmtoff;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return false;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user