DST incorrectly ends on wrong dates
Tested glib versions: 2.62.4 and 2.66.1
Tested OS: Windows 7 and Windows 10
Build environment: MSYS2, MINGW 64bit
Given this simple code:
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <glib.h>
#include <time.h>
int main() {
GTimeZone *tz = g_time_zone_new("Romance Standard Time");
GDateTime *dt = g_date_time_new_now(tz);
gchar *str = g_date_time_format (dt, "%Y-%m-%d %H:%M:%S%z");
puts(str);
return 0;
}
At 13:30:00, 2020-10-02, the program dumps: "2020-10-02 12:30:00+0100". This is not correct for "Romance Standard Time", since we're still in DST so the returned value should be "2020-10-02 13:30:00+0200". I've checked the data in the Windows Registry (where the time zone info is stored) and the binary chunk contains valid settings (i.e. DST ends on the last sunday of October).
I've tried to use the native Windows API by manually loading a TZI structure with the chunk in the Windows Registry, and the result is the expected:
int main() {
TIME_ZONE_INFORMATION tzi;
SYSTEMTIME utc, local;
memset(&tzi, 0, sizeof(tzi));
tzi.Bias = -60;
wcscpy(tzi.StandardName, L"std");
tzi.StandardDate.wMonth = 10;
tzi.StandardDate.wDay = 5;
tzi.StandardDate.wHour = 3;
tzi.StandardBias = 0;
wcscpy(tzi.DaylightName, L"dst");
tzi.DaylightDate.wMonth = 3;
tzi.DaylightDate.wDay = 5;
tzi.DaylightDate.wHour = 2;
tzi.DaylightBias = -60;
GetSystemTime(&utc);
SystemTimeToTzSpecificLocalTime(&tzi, &utc, &local);
printf("%04d-%02d-%02d %02d:%02d:%02d", local.wYear, local.wMonth, local.wDay,
local.wHour, local.wMinute, local.wSecond);
return 0;
}
I have tested with other time zone names and the dumped value differs from the current official time of that zone, so it's a library bug rather than an error in the time zone information stored in the windows registry.
EDIT: the comments below show how the GTimeZone library regularly fails on computing the DST transition times for a given time zone area.