mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
gdate: Reinitialize locale information in g_date_prepare_to_parse.
When g_date_set_parse was used with more than one locale it could incorrectly retain information from previous one. Reinitialize all locale specific data inside g_date_prepare_to_parse to avoid the issue.
This commit is contained in:
parent
d512c0fe43
commit
a8fd91aae5
@ -1132,6 +1132,12 @@ g_date_prepare_to_parse (const gchar *str,
|
||||
|
||||
g_date_fill_parse_tokens (buf, &testpt);
|
||||
|
||||
using_twodigit_years = FALSE;
|
||||
locale_era_adjust = 0;
|
||||
dmy_order[0] = G_DATE_DAY;
|
||||
dmy_order[1] = G_DATE_MONTH;
|
||||
dmy_order[2] = G_DATE_YEAR;
|
||||
|
||||
i = 0;
|
||||
while (i < testpt.num_ints)
|
||||
{
|
||||
|
@ -182,6 +182,32 @@ test_parse (void)
|
||||
g_date_free (d);
|
||||
}
|
||||
|
||||
static void
|
||||
test_parse_locale_change (void)
|
||||
{
|
||||
/* Checks that g_date_set_parse correctly changes locale specific data as
|
||||
* necessary. In this particular case year adjustment, as Thai calendar is
|
||||
* 543 years ahead of the Gregorian calendar. */
|
||||
|
||||
GDate date;
|
||||
|
||||
if (setlocale (LC_ALL, "th_TH") == NULL)
|
||||
{
|
||||
g_test_skip ("locale th_TH not available");
|
||||
return;
|
||||
}
|
||||
|
||||
g_date_set_parse (&date, "04/07/2519");
|
||||
|
||||
setlocale (LC_ALL, "C");
|
||||
g_date_set_parse (&date, "07/04/76");
|
||||
g_assert_cmpint (g_date_get_day (&date), ==, 4);
|
||||
g_assert_cmpint (g_date_get_month (&date), ==, 7);
|
||||
g_assert_cmpint (g_date_get_year (&date), ==, 1976);
|
||||
|
||||
setlocale (LC_ALL, "");
|
||||
}
|
||||
|
||||
static void
|
||||
test_month_names (void)
|
||||
{
|
||||
@ -709,6 +735,7 @@ main (int argc, char** argv)
|
||||
g_test_add_func ("/date/julian", test_julian_constructor);
|
||||
g_test_add_func ("/date/dates", test_dates);
|
||||
g_test_add_func ("/date/parse", test_parse);
|
||||
g_test_add_func ("/date/parse_locale_change", test_parse_locale_change);
|
||||
g_test_add_func ("/date/month_names", test_month_names);
|
||||
g_test_add_func ("/date/clamp", test_clamp);
|
||||
g_test_add_func ("/date/order", test_order);
|
||||
|
Loading…
Reference in New Issue
Block a user