Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

tzcode or glib2 bug?



Hi!

Some weeks/months ago I noticed that some tools displayed the wrong
time, one hour in the future (right now, on 9.99.46/amd64)

I've tracked this down to those using glib2 and wrote a small test
program.

# gcc test.c `pkg-config --cflags glib-2.0` `pkg-config --libs glib-2.0`
# ./a.out; date
local time: 19:22:59
UTC time: 17:22:59
Mo. Feb. 10 18:22:59 CET 2020

I have /etc/localtime symlinked:

lrwxr-xr-x  1 root  wheel  33 May 31  2019 /etc/localtime -> /usr/share/zoneinfo/Europe/Vienna

(and this is handled correctly by glib2) but it doesn't work with
explicitly given TZ environment variable either.

# TZ=Europe/Vienna ./a.out; TZ=Europe/Vienna date
local time: 19:24:45
UTC time: 17:24:45
Mo. Feb. 10 18:24:45 CET 2020

Other timezones work:

# TZ=EST ./a.out; TZ=EST date
local time: 12:24:35
UTC time: 17:24:35
Mo. Feb. 10 12:24:35 EST 2020

Is there something weird in NetBSD's version of tzcode (I see we have
quite some changes) and we notice because glib2 has its own parser, or
is it a bug in glib2?

(I debugged it into glib2 and found that it identifies the timezone
correctly from the symlink and then calls init_zone_from_iana_info(),
see
https://github.com/GNOME/glib/blob/mainline/glib/gtimezone.c#L522.)

 Thomas

#include <glib.h>
#include <stdio.h>

int main() {
    GDateTime *tm = g_date_time_new_now_local();
    char *ts = g_date_time_format(tm, "%H:%M:%S");
    g_date_time_unref(tm);
    printf("local time: %s\n", ts);

    tm = g_date_time_new_now_utc();
    ts = g_date_time_format(tm, "%H:%M:%S");
    g_date_time_unref(tm);
    printf("UTC time: %s\n", ts);
}


Home | Main Index | Thread Index | Old Index