aboutsummaryrefslogtreecommitdiffstats
path: root/e-util/e-util.c
diff options
context:
space:
mode:
authorChristopher James Lahey <clahey@ximian.com>2001-09-23 03:03:48 +0800
committerChris Lahey <clahey@src.gnome.org>2001-09-23 03:03:48 +0800
commit12ecaf7cef7e9a3eea0aa8a7cb44235bd14e507f (patch)
treef5e96bbaab01d5725f9c33b97a52b280197ef189 /e-util/e-util.c
parent8d22486006c1489c2823443aef679d575b05841a (diff)
downloadgsoc2013-evolution-12ecaf7cef7e9a3eea0aa8a7cb44235bd14e507f.tar
gsoc2013-evolution-12ecaf7cef7e9a3eea0aa8a7cb44235bd14e507f.tar.gz
gsoc2013-evolution-12ecaf7cef7e9a3eea0aa8a7cb44235bd14e507f.tar.bz2
gsoc2013-evolution-12ecaf7cef7e9a3eea0aa8a7cb44235bd14e507f.tar.lz
gsoc2013-evolution-12ecaf7cef7e9a3eea0aa8a7cb44235bd14e507f.tar.xz
gsoc2013-evolution-12ecaf7cef7e9a3eea0aa8a7cb44235bd14e507f.tar.zst
gsoc2013-evolution-12ecaf7cef7e9a3eea0aa8a7cb44235bd14e507f.zip
Bumped the version number to 0.12.99.0.
2001-09-22 Christopher James Lahey <clahey@ximian.com> * configure.in: Bumped the version number to 0.12.99.0. From a patch by Damian Ivereigh <damian@cisco.com>: * gal/util/e-util.c, gal/util/e-util.h (e_strftime_fix_am_pm): New function, takes the same arguments as strftime, but does some fixup if the given string is in 12 hour mode but the locale doesn't have AM/PM descriptors. From gal/e-table/ChangeLog: 2001-09-22 Christopher James Lahey <clahey@ximian.com> From a patch by Damian Ivereigh <damian@cisco.com>: * e-cell-date.c: Made this use e_strftime_fix_am_pm instead of strftime. svn path=/trunk/; revision=13081
Diffstat (limited to 'e-util/e-util.c')
-rw-r--r--e-util/e-util.c63
1 files changed, 63 insertions, 0 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);
+}
+