[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH 2/2] qemuxml2argvtest: Set timezone



On 02/06/2014 06:33 AM, Michal Privoznik wrote:
> With my recent work on the test, both time() and localtime() are used.
> While mocking the former one, we get predictible result for UTC. But

s/predictible/predictable/

> since the latter function uses timezone to get local time, the result of
> localtime() is not so predictive. Therefore, we must set the TZ variable
> at the beginning of the test. To be able to catch some things that work
> just by a blind chance, I'm choosing an exotic timezone that (hopefully)
> no libvirt developer resides in.
> 
> Signed-off-by: Michal Privoznik <mprivozn redhat com>
> ---

> +    /* Set the timezone because we are mocking the time() function.
> +     * If we don't do that, then localtime() may return unpredictable
> +     * results. In order to detect things that just work by a blind
> +     * chance, we need to set an exotic timezone that none libvirt

s/none/no/

> +     * developer resides in. So if you go for holiday to Niue, don't
> +     * send patches but enjoy time off! */
> +    if (setenv("TZ", "Pacific/Niue", 1) < 0) {

This works on glibc, but is not portable to all platforms.  I'd prefer
we use a POSIX timezone specification:

http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html

> The expanded format (for all TZ s whose value does not have a <colon> as the first character) is as follows:
> 
> stdoffset[dst[offset][,start[/time],end[/time]]]

In fact, you can abuse offset to list a timezone with a half hour offset
from UTC, with no daylight savings, and then guarantee that no developer
uses that timezone:

$ date --utc
Thu Feb  6 13:52:24 UTC 2014
$ TZ=VIR00:30 date
Thu Feb  6 13:22:43 VIR 2014

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]