[glib/gdate-no-dst] glib/tests/date.c: Fix 2-digit year test



commit ea4a117b597a5277dc7e35cbab177c67bb4fe44d
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Mon Apr 11 15:18:30 2022 +0800

    glib/tests/date.c: Fix 2-digit year test
    
    ...for certain Windows locales, since the formats accepted for
    g_date_set_parse() will vary depending on the current system locale.  For
    instance, g_date_set_parse(gdate, "dd/mm/yy") is accepted on locales such
    as zh-HK (Chinese (Hong Kong SAR)) but is rejected on zh-TW (Chinese
    (Taiwan)).
    
    One can tell from the "date format" settings in the Windows system
    control panel whether there is a "dd/MM/YYYY" or "dd/MM/YY" option from the
    drop-down list of date formats to display for the locale, which will indicate
    whether g_date_set_parse(gdate, "dd/mm/yy") is accepted, which is true for
    zh-HK but is not true for zh-TW.
    
    If g_date_set_parse(gdate, "dd/mm/yy") is not accepted, try again with
    g_date_set_parse(gdate, "yy/mm/dd") thereafter for the 2-digit-year tests.

 glib/tests/date.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
---
diff --git a/glib/tests/date.c b/glib/tests/date.c
index fa441a1501..3effac2457 100644
--- a/glib/tests/date.c
+++ b/glib/tests/date.c
@@ -826,6 +826,8 @@ test_two_digit_years (void)
   GDate *d;
   gchar buf[101];
   gchar *old_locale;
+  gboolean use_alternative_format = FALSE;
+
 #ifdef G_OS_WIN32
   LCID old_lcid;
 #endif
@@ -848,6 +850,15 @@ test_two_digit_years (void)
   g_date_strftime (buf, sizeof (buf), "%D", d);
   g_assert_cmpstr (buf, ==, "10/10/76");
   g_date_set_parse (d, buf);
+
+#ifdef G_OS_WIN32
+  if (!g_date_valid (d))
+    use_alternative_format = TRUE;
+#endif
+
+  if (use_alternative_format)
+    g_date_set_parse (d, "76/10/10");
+
   g_assert_cmpint (g_date_get_month (d), ==, 10);
   g_assert_cmpint (g_date_get_day (d), ==, 10);
   g_assert_true ((g_date_get_year (d) == 1976) ||
@@ -857,7 +868,7 @@ test_two_digit_years (void)
   g_date_set_dmy (d, 10, 10, 29);
   g_date_strftime (buf, sizeof (buf), "%D", d);
   g_assert_cmpstr (buf, ==, "10/10/29");
-  g_date_set_parse (d, buf);
+  g_date_set_parse (d, use_alternative_format ? "29/10/10" : buf);
   g_assert_cmpint (g_date_get_month (d), ==, 10);
   g_assert_cmpint (g_date_get_day (d), ==, 10);
   g_assert_true ((g_date_get_year (d) == 2029) ||


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]