After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 688139 - g_date_time_format() fails when LC_TIME and LC_CTYPE specify different character sets
g_date_time_format() fails when LC_TIME and LC_CTYPE specify different charac...
Status: RESOLVED OBSOLETE
Product: glib
Classification: Platform
Component: i18n
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2012-11-12 05:46 UTC by Gunnar Hjalmarsson
Modified: 2018-05-24 14:49 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
test.c (1.20 KB, text/plain)
2012-11-12 05:46 UTC, Gunnar Hjalmarsson
Details

Description Gunnar Hjalmarsson 2012-11-12 05:46:10 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.
Comment 1 Dan Winship 2012-11-12 12:11:12 UTC
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.
Comment 2 Gunnar Hjalmarsson 2012-11-12 20:15:51 UTC
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.
Comment 3 GNOME Infrastructure Team 2018-05-24 14:49:11 UTC
-- 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.