Time format not taken from LC_TIME

Bug #652976 reported by Michael Terry on 2010-10-01
This bug affects 6 people
Affects Status Importance Assigned to Milestone
Indicator Date and Time
Fix Released
Michael Terry
Ubuntu Translations
indicator-datetime (Ubuntu)

Bug Description

Binary package hint: indicator-datetime

This is a break-out bug from bug 579134.

Whether time is formatted as 24h or not should be taken from LC_TIME.

Unfortunately, locales don't provide an easy way to ask the question "Is time in 24h format?". strftime provide a couple format strings like %X that give the preferred format string, but %X always includes seconds. So you can either strip seconds in some clever way or find another way to ask the question.

Asking whether fields like AM_STR, PM_STR, or T_FMT_AMPM are defined is not definitive. 24h locales like en_GB may define those because it wants to provide a known way to format 12h if asked for it (i.e. 12h is not unheard of in en_GB and does have preferred representations if the caller knows they want 12h).

The only way I've seen in my searches is to parse the value of T_FMT and see if it includes 24h format strings. Which is only slightly cleaner than stripping seconds from %X.

I'm attaching a testing program that works for me. Compile it like so: gcc -o is24 is24.c

$ LC_TIME="en_US.UTF-8" ./is24h
T_FMT: %r
Is 24h: no
$ LC_TIME="en_GB.UTF-8" ./is24h
Is 24h: yes
$ LC_TIME="zh_TW.UTF-8" ./is24h
T_FMT: %H:%M:%S
Is 24h: yes

Related branches

Michael Terry (mterry) wrote :
Didier Roche (didrocks) wrote :

just see https://bugs.edge.launchpad.net/indicator-datetime/+bug/579134/comments/19

You can discuss this next week with ted, I think

Michael Terry (mterry) wrote :

Trying to keep the LC_TIME talk here, I'll copy your message:

"it's unlikely LC_TIME will work as ted's approach is to realy on LANG locale and picking up a string from translation. If you run it under LANG="en_GB.UTF-8", that should work (even if it doesn't respect the spec)"

Well, no. (A) indicator-datetime does not have an en_GB translation and (B) the point of this bug is that it shouldn't be using LC_MESSAGES (which is what gettext uses) for time formatting, but rather LC_TIME.

It's perfectly reasonable to set one locale for message strings and another for time. The Language Support program explicitly allows you to do this via the GUI, so it's not just some hacker thing. I do it because I want US strings, but I like 24h time.

Didier Roche (didrocks) wrote :

(B) I totally agree :) Just trying to explain to you why it didn't work.

Michael Vogt (mvo) wrote :

Fwiw, I use en_DK and expect 24h time format with that, but I got 12h format.

@mterry: Your test program seems to give the correct result, but -- what will you do with the 24/12hr information in the end? There is "%R" for a locale-dependent 24h format without seconds but no equivalent for 12h that I'm aware of. Simply using "%I:%M %p" for 12hr locales would not make everyone happy.

I think using translations might actually work if you use a little hack, something along the lines of:
char *message_locale = setlocale(LC_MESSAGES, NULL);
char *time_locale = setlocale(LC_TIME, NULL);
setlocale(LC_MESSAGES, time_locale);
char *time_format = _("%I:%M %p"); /* This will be translated using the PO file corresponding to LC_TIME!*/
setlocale(LC_MESSAGES, message_locale);

Michael Terry (mterry) wrote :

Good point. Or even easier, using dcgettext, which lets you specify a category. I'll whip up a patch.

Changed in indicator-datetime:
assignee: nobody → Michael Terry (mterry)
status: New → In Progress

Oh, of course, that makes it much less hackish -- I was so used to the _("...") makro that I forgot the function call behind it ;)

Michael Terry (mterry) wrote :

Marcel, dcgetext didn't actually do what I wanted after all. I ended up using a modified version of your function that also made sure LANGUAGE was unset (because that trumps LC_*). I also used my function for determining 12h/24h and made a few more fixups. See this bug's merge request.

Ted Gould (ted) on 2011-01-07
Changed in indicator-datetime:
status: In Progress → Fix Committed
milestone: none → 0.1.91
Ted Gould (ted) on 2011-01-27
Changed in indicator-datetime:
status: Fix Committed → Fix Released
Nobuto Murata (nobuto) wrote :

Natty's current package is 0.1.90.is.0.0.6-0ubuntu2 which does not contain this fix yet.

Changed in indicator-datetime (Ubuntu):
status: New → Confirmed
tags: added: iso-testing
Changed in indicator-datetime (Ubuntu):
status: Confirmed → Fix Released
David Planella (dpm) on 2011-03-04
Changed in ubuntu-translations:
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers

Bug attachments