GNOME Bugzilla – Bug 688139
g_date_time_format() fails when LC_TIME and LC_CTYPE specify different character sets
Last modified: 2018-05-24 14:49:11 UTC
Created attachment 228749 [details] test.c Running the attached script results in the following: <output> C locale -------- first_day %a: Mon first_day %A: Monday first_day %c: Mon Nov 12 00:00:00 2012 second_day %a: Tue second_day %A: Tuesday second_day %c: Tue Nov 13 00:00:00 2012 Swedish locale -------------- first_day %a: (null) first_day %A: (null) first_day %c: (null) second_day %a: tis second_day %A: tisdag second_day %c: tis 13 nov 2012 00:00:00 </output> The first day of the week is spelled "måndag" in Swedish. g_date_time_format() seems to have a problem because "måndag" includes a non-ascii character.
So the short answer for you is probably: 'you forgot to call setlocale(LC_ALL, "");' At a higher level, this is related to bug 687945; we are assuming that the day/month strings returned from nl_langinfo() are in the character set returned by g_get_charset(). Which is to say, we are assuming that LC_TIME and LC_CTYPE match. In this test program, LC_CTYPE is "C", so g_get_charset() returns ASCII, so g_date_time_format() thinks it needs to translate "måndag" from ASCII to UTF-8, and that fails because it's not ASCII to begin with.
Thanks for the explanation, Dan! Considering that the need to set LC_ALL (or both LC_TIME and LC_CTYPE) with setlocale() differs from strftime(), I can think it would be motivated to mention it in the g_date_time_format() section of the reference manual.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/629.