[libvirt] [PATCHv2 1/4] util: new function virTimeLocalOffsetFromUTC
Eric Blake
eblake at redhat.com
Thu May 22 17:39:06 UTC 2014
On 05/22/2014 05:07 AM, Laine Stump wrote:
> Since there isn't a single libc API to get this value, this patch
> supplies one which gets the value by grabbing current UTC, then
> converting that into a struct tm with localtime_r(), then back to a
> time_t using mktime; it again does the same operation, but using
> gmtime_r() instead (for UTC). It then subtracts utc time from the
> localtime, and finally adjusts if dst is set in the localtime timeinfo
> (because for some reason mktime doesn't take that into account).
>
> 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.
> ---
>
> Change from V1: add test cases with TZ set to different values (if
> someone knows how to force DST on/off, I would gladly add some test
> cases for this as well).
Re-reading POSIX:
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html
I think you can do something like:
VIR00:30VID
where "VIR" is the normal time, and "VID" is the daylight-savings time 1
hour ahead. It was the absence of a second name that made POSIX treat
the TZ value as not having daylight savings.
I'll review the actual patch in another mail.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 604 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140522/583d1cbb/attachment-0001.sig>
More information about the libvir-list
mailing list