Merge branch 'wip/smcv/pst8pdt' into 'main'

gdatetime test: Fix regression with tzdata 2024b

Closes #3502

See merge request GNOME/glib!4356
This commit is contained in:
Philip Withnall 2024-10-18 11:06:41 +00:00
commit 857b418b48

View File

@ -2931,6 +2931,8 @@ test_posix_parse (void)
{
GTimeZone *tz;
GDateTime *gdt1, *gdt2;
gint i1, i2;
const char *expect_id;
/* Check that an unknown zone name falls back to UTC. */
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
@ -2953,18 +2955,40 @@ test_posix_parse (void)
g_time_zone_unref (tz);
/* This fails rules_from_identifier on Unix (though not on Windows)
* but passes anyway because PST8PDT is a zone name.
* but can pass anyway because PST8PDT is a legacy System V zone name.
*/
tz = g_time_zone_new_identifier ("PST8PDT");
expect_id = "PST8PDT";
#ifndef G_OS_WIN32
/* PST8PDT is in tzdata's "backward" set, packaged as tzdata-legacy and
* not always present in some OSs; fall back to the equivalent geographical
* name if the "backward" time zones are absent. */
if (tz == NULL)
{
g_test_message ("Legacy PST8PDT time zone not available, falling back");
tz = g_time_zone_new_identifier ("America/Los_Angeles");
expect_id = "America/Los_Angeles";
}
#endif
g_assert_nonnull (tz);
g_assert_cmpstr (g_time_zone_get_identifier (tz), ==, "PST8PDT");
g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 0), ==, "PST");
g_assert_cmpint (g_time_zone_get_offset (tz, 0), ==, - 8 * 3600);
g_assert (!g_time_zone_is_dst (tz, 0));
g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 1), ==, "PDT");
g_assert_cmpint (g_time_zone_get_offset (tz, 1), ==,- 7 * 3600);
g_assert (g_time_zone_is_dst (tz, 1));
g_assert_cmpstr (g_time_zone_get_identifier (tz), ==, expect_id);
/* a date in winter = non-DST */
gdt1 = g_date_time_new (tz, 2024, 1, 1, 0, 0, 0);
i1 = g_time_zone_find_interval (tz, G_TIME_TYPE_STANDARD, g_date_time_to_unix (gdt1));
/* a date in summer = DST */
gdt2 = g_date_time_new (tz, 2024, 7, 1, 0, 0, 0);
i2 = g_time_zone_find_interval (tz, G_TIME_TYPE_DAYLIGHT, g_date_time_to_unix (gdt2));
g_assert_cmpstr (g_time_zone_get_abbreviation (tz, i1), ==, "PST");
g_assert_cmpint (g_time_zone_get_offset (tz, i1), ==, - 8 * 3600);
g_assert (!g_time_zone_is_dst (tz, i1));
g_assert_cmpstr (g_time_zone_get_abbreviation (tz, i2), ==, "PDT");
g_assert_cmpint (g_time_zone_get_offset (tz, i2), ==,- 7 * 3600);
g_assert (g_time_zone_is_dst (tz, i2));
g_time_zone_unref (tz);
g_date_time_unref (gdt1);
g_date_time_unref (gdt2);
tz = g_time_zone_new_identifier ("PST8PDT6:32:15");
#ifdef G_OS_WIN32