gtimezone.c: Fix identifier assignment on Windows

On Windows, we may be using the US DST boundaries by using the default
"Pacific Standard Time" for rules_from_windows_time_zone() in
rules_from_identifier().  This has the unfortunate side-effect of
hardcoding the out_identifier to "Pacific Standard Time", which is
likely not what we want.

Instead, upon retrieving the items successfully using
rules_from_windows_time_zone ("Pacific Standard Time", ...), we just
set the out_identifier to whatever identifier that was passed into
rules_from_identifier().
This commit is contained in:
Chun-wei Fan 2019-06-13 16:28:47 +08:00
parent 5ca4ac16ef
commit f24444c585

View File

@ -717,7 +717,8 @@ register_tzi_to_tzi (RegTZI *reg, TIME_ZONE_INFORMATION *tzi)
static guint
rules_from_windows_time_zone (const gchar *identifier,
gchar **out_identifier,
TimeZoneRule **rules)
TimeZoneRule **rules,
gboolean copy_identifier)
{
HKEY key;
gchar *subkey = NULL;
@ -735,10 +736,12 @@ rules_from_windows_time_zone (const gchar *identifier,
if (GetSystemDirectoryW (winsyspath, MAX_PATH) == 0)
return 0;
g_assert (out_identifier != NULL);
g_assert (copy_identifier == FALSE || out_identifier != NULL);
g_assert (rules != NULL);
*out_identifier = NULL;
if (copy_identifier)
*out_identifier = NULL;
*rules = NULL;
key_name = NULL;
@ -888,7 +891,10 @@ utf16_conv_failed:
else
(*rules)[rules_num - 1].start_year = (*rules)[rules_num - 2].start_year + 1;
*out_identifier = g_steal_pointer (&key_name);
if (copy_identifier)
*out_identifier = g_steal_pointer (&key_name);
else
g_free (key_name);
return rules_num;
}
@ -1425,9 +1431,15 @@ rules_from_identifier (const gchar *identifier,
/* Use US rules, Windows' default is Pacific Standard Time */
if ((rules_num = rules_from_windows_time_zone ("Pacific Standard Time",
out_identifier,
rules)))
NULL,
rules,
FALSE)))
{
/* We don't want to hardcode our identifier here as
* "Pacific Standard Time", use what was passed in
*/
*out_identifier = g_strdup (identifier);
for (i = 0; i < rules_num - 1; i++)
{
(*rules)[i].std_offset = - tzr.std_offset;
@ -1572,7 +1584,8 @@ g_time_zone_new (const gchar *identifier)
#elif defined (G_OS_WIN32)
if ((rules_num = rules_from_windows_time_zone (identifier,
&resolved_identifier,
&rules)))
&rules,
TRUE)))
{
init_zone_from_rules (tz, rules, rules_num, g_steal_pointer (&resolved_identifier));
g_free (rules);