mirror of
				https://gitlab.gnome.org/GNOME/glib.git
				synced 2025-11-04 01:58:54 +01:00 
			
		
		
		
	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.
This commit is contained in:
		
				
					committed by
					
						
						Philip Withnall
					
				
			
			
				
	
			
			
			
						parent
						
							b47e7b3503
						
					
				
				
					commit
					ccc2a73e86
				
			@@ -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,25 @@ 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
 | 
			
		||||
  /*
 | 
			
		||||
   * It depends on the locale setting whether the dd/mm/yy
 | 
			
		||||
   * format is allowed for g_date_set_parse() on Windows, which
 | 
			
		||||
   * corresponds to whether there is an d/M/YY or d/M/YYYY (or so)
 | 
			
		||||
   * option in the "Date and Time Format" setting for the selected
 | 
			
		||||
   * locale in the Control Panel settings.  If g_date_set_parse()
 | 
			
		||||
   * renders the GDate invalid with the dd/mm/yy format, use an
 | 
			
		||||
   * alternative format (yy/mm/dd) for g_date_set_parse() for the
 | 
			
		||||
   * 2-digit year tests.
 | 
			
		||||
   */
 | 
			
		||||
  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 +878,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) ||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user