127 lines
5.1 KiB
Diff
127 lines
5.1 KiB
Diff
From a07f759373d888c837a780cb93f14542b029e19c Mon Sep 17 00:00:00 2001
|
|
From: "Rebecca N. Palmer" <rebecca_palmer@zoho.com>
|
|
Date: Fri, 11 Oct 2024 09:38:52 +0100
|
|
Subject: [PATCH 1/2] gdatetime test: Do not assume PST8PDT was always exactly
|
|
-8/-7
|
|
|
|
In newer tzdata, it is an alias for America/Los_Angeles, which has a
|
|
slightly different meaning: DST did not exist there before 1883. As a
|
|
result, we can no longer hard-code the knowledge that interval 0 is
|
|
standard time and interval 1 is summer time, and instead we need to look
|
|
up the correct intervals from known timestamps.
|
|
|
|
Resolves: https://gitlab.gnome.org/GNOME/glib/-/issues/3502
|
|
Bug-Debian: https://bugs.debian.org/1084190
|
|
[smcv: expand commit message, fix whitespace]
|
|
Signed-off-by: Simon McVittie <smcv@debian.org>
|
|
---
|
|
glib/tests/gdatetime.c | 23 +++++++++++++++++------
|
|
1 file changed, 17 insertions(+), 6 deletions(-)
|
|
|
|
diff --git a/glib/tests/gdatetime.c b/glib/tests/gdatetime.c
|
|
index 5a2190d5f..80098bab3 100644
|
|
--- a/glib/tests/gdatetime.c
|
|
+++ b/glib/tests/gdatetime.c
|
|
@@ -2096,6 +2096,7 @@ test_posix_parse (void)
|
|
{
|
|
GTimeZone *tz;
|
|
GDateTime *gdt1, *gdt2;
|
|
+ gint i1, i2;
|
|
|
|
tz = g_time_zone_new ("PST");
|
|
g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 0), ==, "UTC");
|
|
@@ -2111,14 +2112,24 @@ test_posix_parse (void)
|
|
|
|
/* This fails rules_from_identifier on Unix (though not on Windows)
|
|
* but passes anyway because PST8PDT is a zone name.
|
|
+ *
|
|
+ * Intervals i1 and i2 (rather than 0 and 1) are needed because in
|
|
+ * recent tzdata, PST8PDT may be an alias for America/Los_Angeles,
|
|
+ * and hence be aware that DST has not always existed.
|
|
+ * https://bugs.debian.org/1084190
|
|
*/
|
|
tz = g_time_zone_new ("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_nonnull (tz);
|
|
+ /* a date in winter = non-DST */
|
|
+ i1 = g_time_zone_find_interval (tz, G_TIME_TYPE_STANDARD, 0);
|
|
+ /* approximately 6 months in seconds, i.e. a date in summer = DST */
|
|
+ i2 = g_time_zone_find_interval (tz, G_TIME_TYPE_DAYLIGHT, 15000000);
|
|
+ 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);
|
|
|
|
tz = g_time_zone_new ("PST8PDT6:32:15");
|
|
--
|
|
2.50.0
|
|
|
|
|
|
From d1e564d6d4f478c9e0b163763ed2b199dfafd500 Mon Sep 17 00:00:00 2001
|
|
From: Simon McVittie <smcv@debian.org>
|
|
Date: Fri, 18 Oct 2024 11:03:19 +0100
|
|
Subject: [PATCH 2/2] gdatetime test: Try to make PST8PDT test more obviously
|
|
correct
|
|
|
|
Instead of using timestamp 0 as a magic number (in this case interpreted
|
|
as 1970-01-01T00:00:00-08:00), calculate a timestamp from a recent
|
|
year/month/day in winter, in this case 2024-01-01T00:00:00-08:00.
|
|
|
|
Similarly, instead of using a timestamp 15 million seconds later
|
|
(1970-06-23T15:40:00-07:00), calculate a timestamp from a recent
|
|
year/month/day in summer, in this case 2024-07-01T00:00:00-07:00.
|
|
|
|
Signed-off-by: Simon McVittie <smcv@debian.org>
|
|
---
|
|
glib/tests/gdatetime.c | 15 +++++++--------
|
|
1 file changed, 7 insertions(+), 8 deletions(-)
|
|
|
|
diff --git a/glib/tests/gdatetime.c b/glib/tests/gdatetime.c
|
|
index 80098bab3..d0755e722 100644
|
|
--- a/glib/tests/gdatetime.c
|
|
+++ b/glib/tests/gdatetime.c
|
|
@@ -2112,18 +2112,15 @@ test_posix_parse (void)
|
|
|
|
/* This fails rules_from_identifier on Unix (though not on Windows)
|
|
* but passes anyway because PST8PDT is a zone name.
|
|
- *
|
|
- * Intervals i1 and i2 (rather than 0 and 1) are needed because in
|
|
- * recent tzdata, PST8PDT may be an alias for America/Los_Angeles,
|
|
- * and hence be aware that DST has not always existed.
|
|
- * https://bugs.debian.org/1084190
|
|
*/
|
|
tz = g_time_zone_new ("PST8PDT");
|
|
g_assert_nonnull (tz);
|
|
/* a date in winter = non-DST */
|
|
- i1 = g_time_zone_find_interval (tz, G_TIME_TYPE_STANDARD, 0);
|
|
- /* approximately 6 months in seconds, i.e. a date in summer = DST */
|
|
- i2 = g_time_zone_find_interval (tz, G_TIME_TYPE_DAYLIGHT, 15000000);
|
|
+ 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));
|
|
@@ -2131,6 +2128,8 @@ test_posix_parse (void)
|
|
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 ("PST8PDT6:32:15");
|
|
#ifdef G_OS_WIN32
|
|
--
|
|
2.50.0
|
|
|