aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--e-util/e-util.c63
-rw-r--r--e-util/e-util.h4
-rw-r--r--widgets/table/e-cell-date.c14
3 files changed, 74 insertions, 7 deletions
diff --git a/e-util/e-util.c b/e-util/e-util.c
index fb18db91ca..d3479a6661 100644
--- a/e-util/e-util.c
+++ b/e-util/e-util.c
@@ -31,6 +31,7 @@
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
+#include <time.h>
#include "e-util.h"
#if 0
@@ -1115,3 +1116,65 @@ e_sort (void *base,
g_free(base_copy);
#endif
}
+
+/**
+ * Function to do a last minute fixup of the AM/PM stuff if the locale
+ * and gettext haven't done it right. Most English speaking countries
+ * except the USA use the 24 hour clock (UK, Australia etc). However
+ * since they are English nobody bothers to write a language
+ * translation (gettext) file. So the locale turns off the AM/PM, but
+ * gettext does not turn on the 24 hour clock. Leaving a mess.
+ *
+ * This routine checks if AM/PM are defined in the locale, if not it
+ * forces the use of the 24 hour clock.
+ *
+ * The function itself is a front end on strftime and takes exactly
+ * the same arguments.
+ *
+ * TODO: Actually remove the '%p' from the fixed up string so that
+ * there isn't a stray space.
+ **/
+
+size_t e_strftime_fix_am_pm(char *s, size_t max, const char *fmt, const struct tm *tm)
+{
+ char buf[10];
+ char *sp;
+ char *ffmt;
+ size_t ret;
+
+ if (strstr(fmt, "%p")==NULL && strstr(fmt, "%P")==NULL) {
+ /* No AM/PM involved - can use the fmt string directly */
+ ret=strftime(s, max, fmt, tm);
+ } else {
+ /* Get the AM/PM symbol from the locale */
+ strftime (buf, 10, "%p", tm);
+
+ if (buf[0]) {
+ /**
+ * AM/PM have been defined in the locale
+ * so we can use the fmt string directly
+ **/
+ ret=strftime(s, max, fmt, tm);
+ } else {
+ /**
+ * No AM/PM defined by locale
+ * must change to 24 hour clock
+ **/
+ ffmt=g_strdup(fmt);
+ for (sp=ffmt; (sp=strstr(sp, "%l")); sp++) {
+ /**
+ * Maybe this should be 'k', but I have never
+ * seen a 24 clock actually use that format
+ **/
+ sp[1]='H';
+ }
+ for (sp=ffmt; (sp=strstr(sp, "%I")); sp++) {
+ sp[1]='H';
+ }
+ ret=strftime(s, max, ffmt, tm);
+ g_free(ffmt);
+ }
+ }
+ return(ret);
+}
+
diff --git a/e-util/e-util.h b/e-util/e-util.h
index 8f99e0f8d5..22b96a376a 100644
--- a/e-util/e-util.h
+++ b/e-util/e-util.h
@@ -103,6 +103,10 @@ void e_bsearch (cons
gpointer closure,
size_t *start,
size_t *end);
+size_t e_strftime_fix_am_pm (char *s,
+ size_t max,
+ const char *fmt,
+ const struct tm *tm);
void e_marshal_INT__INT_INT_POINTER (GtkObject *object,
GtkSignalFunc func,
gpointer func_data,
diff --git a/widgets/table/e-cell-date.c b/widgets/table/e-cell-date.c
index 2c1873ae90..a483d79d89 100644
--- a/widgets/table/e-cell-date.c
+++ b/widgets/table/e-cell-date.c
@@ -39,7 +39,7 @@ ecd_get_text(ECellText *cell, ETableModel *model, int col, int row)
localtime_r (&nowdate, &now);
if (nowdate - date < 60 * 60 * 8 && nowdate > date) {
- strftime (buf, 26, _("%l:%M %p"), &then);
+ e_strftime_fix_am_pm (buf, 26, _("%l:%M %p"), &then);
done = TRUE;
}
@@ -47,7 +47,7 @@ ecd_get_text(ECellText *cell, ETableModel *model, int col, int row)
if (then.tm_mday == now.tm_mday &&
then.tm_mon == now.tm_mon &&
then.tm_year == now.tm_year) {
- strftime (buf, 26, _("Today %l:%M %p"), &then);
+ e_strftime_fix_am_pm (buf, 26, _("Today %l:%M %p"), &then);
done = TRUE;
}
}
@@ -59,10 +59,10 @@ ecd_get_text(ECellText *cell, ETableModel *model, int col, int row)
then.tm_year == yesterday.tm_year) {
#if 0
if (nowdate - date < 60 * 60 * 12) {
- strftime (buf, 26, _("Late Yesterday %l:%M %p"), &then);
+ e_strftime_fix_am_pm (buf, 26, _("Late Yesterday %l:%M %p"), &then);
} else {
#endif
- strftime (buf, 26, _("Yesterday %l:%M %p"), &then);
+ e_strftime_fix_am_pm (buf, 26, _("Yesterday %l:%M %p"), &then);
#if 0
}
#endif
@@ -77,7 +77,7 @@ ecd_get_text(ECellText *cell, ETableModel *model, int col, int row)
if (then.tm_mday == yesterday.tm_mday &&
then.tm_mon == yesterday.tm_mon &&
then.tm_year == yesterday.tm_year) {
- strftime (buf, 26, _("%a %l:%M %p"), &then);
+ e_strftime_fix_am_pm (buf, 26, _("%a %l:%M %p"), &then);
done = TRUE;
break;
}
@@ -85,9 +85,9 @@ ecd_get_text(ECellText *cell, ETableModel *model, int col, int row)
}
if (!done) {
if (then.tm_year == now.tm_year) {
- strftime (buf, 26, _("%b %d %l:%M %p"), &then);
+ e_strftime_fix_am_pm (buf, 26, _("%b %d %l:%M %p"), &then);
} else {
- strftime (buf, 26, _("%b %d %Y"), &then);
+ e_strftime_fix_am_pm (buf, 26, _("%b %d %Y"), &then);
}
}
#if 0