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 323289 - bad time in mail appointments (12hour without AM/PM in 24hour locales)
bad time in mail appointments (12hour without AM/PM in 24hour locales)
Status: RESOLVED DUPLICATE of bug 205137
Product: evolution
Classification: Applications
Component: Calendar
2.4.x (obsolete)
Other Linux
: Normal major
: ---
Assigned To: evolution-calendar-maintainers
Evolution QA team
Depends on:
Blocks: 327508 327510 336253
 
 
Reported: 2005-12-05 18:15 UTC by Stanislav Brabec
Modified: 2013-09-10 14:04 UTC
See Also:
GNOME target: ---
GNOME version: 2.11/2.12



Description Stanislav Brabec 2005-12-05 18:15:02 UTC
Version details: evolution-2.4.1 evolution-data-server-1.4.1

1. Create an appointment 19:00-20:00
2. Send it by mail to yourself

Actual result:
Appointment displayed as 07:00-08:00
And bad surprise after accept: Appointments is scheduled 12 hours later than it
is displayed to you.

Expected result:
Appointment displayed as 19:00-20:00 (or in worst case as 07:00 PM-08:00 PM).

3. Accept appointment

Additional note:
locale used: LANG=cs_CZ.UTF-8
Comment 1 Stanislav Brabec 2005-12-05 18:35:59 UTC
Seems to be problem of cs.po (sk_SK.UTF-8 shows dates correctly), but I do not
see, which string is bad.
Comment 2 André Klapper 2005-12-05 23:17:28 UTC
hi stanislav, dup of bug 314124?
setting to NEEDINFO, please reopen after answering.
Comment 3 Stanislav Brabec 2005-12-06 13:23:17 UTC
It is the same bug, the same string, but in different locale.

Translators probably follow  misleading time format comment and use %l or %I
(comment says them, that they should use 12-hour format {this comment comes from
the source}). But in European locales, use of %l seems to be illegal, because %p
returns empty string, at least in many of these locales.

Bug 314124 must be fixed in de.po, this bug in cs.po.

I guess that there are more occurrences of this bug in other locales.

sbrabec:~> LANG=C date +%l%p
 2PM
sbrabec:~> LANG=de_DE.UTF-8 date +%l%p
 2
sbrabec:~> LANG=sk_SK.UTF-8 date +%l%p
 2
sbrabec:~> LANG=en_US.UTF-8 date +%l%p
 2PM
Comment 4 Miloslav Trmac 2005-12-11 21:53:00 UTC
Hopefully fixed in CVS, both on HEAD and gnome-2.12.

Thanks for your report.
Comment 5 Stanislav Brabec 2005-12-12 13:09:21 UTC
Reopening bug. It was fixed only for cs locale, but it affects more locales and
source, which gives bad translation instructions.
Comment 6 Chenthill P 2005-12-20 18:32:33 UTC
Confirming the bug based on the above comments.
Comment 7 Steve Fosdick 2006-02-14 15:44:44 UTC
This bug also affects the en_GB.UTF-8 locale.

Interestingly, while the date(1) command returns the empty string for '%p' in this locale as with those listed by Stanislav Brabec earlier, the C library strftime function which takes a similar format string returns AM/PM for all these locales.

$ LANG=en_GB date +%l%p
 2

Compare with this C program:

#include <stdio.h>
#include <time.h>

int main(int argc, char **argv)
{
    time_t now;
    struct tm *tp;
    char tm_str[40];

    time(&now);
    tp = localtime(&now);
    strftime(tm_str, sizeof(tm_str), "%l%p", tp);
    puts(tm_str);
    return 0;
}

When run at 14:43 it gives the following output:

 2PM

It seems the writers of date(1) and strftime(3) took two different approaches to this issue.  For strftime(3) it seems to return AM/PM unless there is a translation and for date(1) it returns the empty string if there isn't a translation.

As far as I know the 24 hour clock is widely used in Europe which perhaps explains the absense of translations for AP/PM in many European locales though 24 hour and 12 hour clock are both in use in the UK.  In the UK, at least, the inclusion of a leading zero on a time effectively says "this is 24 hour clock" so whereas a time of 2:45 is abiguous but would probably be assumed to be in the afternoon, 02:45 is clearly in the middle of the night.

One solution would be that if a locale defines AM/PM translations we assume that means 12 clock is the norm for that locale and we should use it, otherwise we should assume 24 hour clock.  The following short C program demonstrates how this could be done:

#include <langinfo.h>
#include <locale.h>
#include <stdio.h>
#include <time.h>

int main(int argc, char **argv)
{
    const char *am_str;
    const char *format;
    time_t now;
    struct tm *tp;
    char tm_str[40];

    setlocale(LC_ALL, "");
    am_str = nl_langinfo(AM_STR);
    format = (am_str && *am_str) ? "%l:%M %p" : "%H:%M";

    time(&now);
    tp = localtime(&now);
    strftime(tm_str, sizeof(tm_str), format, tp);
    puts(tm_str);
    return 0;
}

As an example, compiling this to an executable called 'td' it gives:

$ LANG=C ./td
 3:35 PM
$ LANG=en_US.UTF-8 ./td
 3:35 PM
$ LANG=en_GB.UTF-8 ./td
15:35
$ LANG=de_DE.UTF-8 ./td
15:35
$ LANG=sk_SK.UTF-8 ./td
15:35

There is a further, minor, issue in that the user can set LANG to a locale that has not been built for the C library installed on their system.  In this case it will default to the C locale behaviour which would give 12 hour clock output.  If it is desired to give 24 hour output in this case an extra test can be introduced:

#include <langinfo.h>
#include <locale.h>
#include <stdio.h>
#include <time.h>

int main(int argc, char **argv)
{
    const char *locale_name;
    const char *am_str;
    const char *format;
    time_t now;
    struct tm *tp;
    char tm_str[40];

    am_str = NULL;
    if ((locale_name = setlocale(LC_ALL, "")) && strcmp(locale_name, "C"))
        am_str = nl_langinfo(AM_STR);
    format = (am_str && *am_str) ? "%l:%M %p" : "%H:%M";

    time(&now);
    tp = localtime(&now);
    strftime(tm_str, sizeof(tm_str), format, tp);
    puts(tm_str);
    return 0;
}

Hope that helps,
Steve.
Comment 8 Steve Fosdick 2006-02-14 15:56:19 UTC
Further to my last message both date(1) and strftime(3) support %X which appears to do the right thing provided the locale concerned has been built.  If not it defaults to 24 hour clock.
Comment 9 Daniel Holbach 2006-03-30 12:42:07 UTC
Reported as https://launchpad.net/distros/ubuntu/+source/evolution/+bug/35602 as well.
Comment 10 Milan Crha 2009-07-03 09:00:42 UTC
I would use for this a more general bug report, thus marking as a duplicate.

*** This bug has been marked as a duplicate of 205137 ***