1cddaea util: new function virTimeLocalOffsetFromUTC

Authored and Committed by Laine Stump 9 years ago
    util: new function virTimeLocalOffsetFromUTC
    
    Since there isn't a single libc API to get this value, this patch
    supplies one which gets the value by grabbing current time, then
    converting that into a struct tm with gmtime_r(), then back to a
    time_t using mktime.
    
    The returned value is the difference between UTC and localtime in
    seconds. If localtime is ahead of UTC (east) the offset will be a
    positive number, and if localtime is behind UTC (west) the offset will
    be negative.
    
    This function should be POSIX-compliant, and is threadsafe, but not
    async signal safe. If it was ever necessary to know this value in a
    child process, we could cache it with a one-time init function when
    libvirtd starts, then just supply the cached value, but that
    complexity isn't needed for current usage; that would also have the
    problem that it might not be accurate after a local daylight savings
    boundary.
    
    (If it weren't for DST, we could simply replace this entire function
    with "-timezone"; timezone contains the offset of the current timezone
    (negated from what we want) but doesn't account for DST. And in spite
    of being guaranteed by POSIX, it isn't available on older versions of
    mingw.)
    
    Signed-off-by: Eric Blake <eblake@redhat.com>
    
        
file modified
+1 -0
file modified
+44 -1
file modified
+3 -2
file modified
+58 -0