aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--e-util/e-util.c43
-rw-r--r--e-util/e-util.h10
-rw-r--r--widgets/table/e-cell-date.c35
3 files changed, 62 insertions, 26 deletions
diff --git a/e-util/e-util.c b/e-util/e-util.c
index 46be2143f7..03fda380e1 100644
--- a/e-util/e-util.c
+++ b/e-util/e-util.c
@@ -768,6 +768,27 @@ size_t e_strftime(char *s, size_t max, const char *fmt, const struct tm *tm)
#endif
}
+size_t
+e_utf8_strftime(char *s, size_t max, const char *fmt, const struct tm *tm)
+{
+ size_t sz;
+ char *locale_fmt = g_locale_from_utf8(fmt, -1, NULL, &sz, NULL);
+ size_t ret = e_strftime(s, max, locale_fmt, tm);
+ char *buf = g_locale_to_utf8(s, ret, NULL, &sz, NULL);
+ if (sz >= max) {
+ char *tmp = buf + max - 1;
+ tmp = g_utf8_find_prev_char(buf, tmp);
+ if (tmp)
+ sz = tmp - buf;
+ else
+ sz = 0;
+ }
+ memcpy(s, buf, sz);
+ s[sz] = '\0';
+ g_free(locale_fmt);
+ g_free(buf);
+ return sz;
+}
/**
* Function to do a last minute fixup of the AM/PM stuff if the locale
@@ -830,6 +851,28 @@ size_t e_strftime_fix_am_pm(char *s, size_t max, const char *fmt, const struct t
return(ret);
}
+size_t
+e_utf8_strftime_fix_am_pm(char *s, size_t max, const char *fmt, const struct tm *tm)
+{
+ size_t sz;
+ char *locale_fmt = g_locale_from_utf8(fmt, -1, NULL, &sz, NULL);
+ size_t ret = e_strftime_fix_am_pm(s, max, locale_fmt, tm);
+ char *buf = g_locale_to_utf8(s, ret, NULL, &sz, NULL);
+ if (sz >= max) {
+ char *tmp = buf + max - 1;
+ tmp = g_utf8_find_prev_char(buf, tmp);
+ if (tmp)
+ sz = tmp - buf;
+ else
+ sz = 0;
+ }
+ memcpy(s, buf, sz);
+ s[sz] = '\0';
+ g_free(locale_fmt);
+ g_free(buf);
+ return sz;
+}
+
/**
* e_flexible_strtod:
* @nptr: the string to convert to a numeric value.
diff --git a/e-util/e-util.h b/e-util/e-util.h
index 2937265f6b..d9d51967d1 100644
--- a/e-util/e-util.h
+++ b/e-util/e-util.h
@@ -196,6 +196,16 @@ size_t e_strftime (char *s,
const char *fmt,
const struct tm *tm);
+size_t e_utf8_strftime_fix_am_pm (char *s,
+ size_t max,
+ const char *fmt,
+ const struct tm *tm);
+
+size_t e_utf8_strftime (char *s,
+ size_t max,
+ const char *fmt,
+ const struct tm *tm);
+
/* String to/from double conversion functions */
gdouble e_flexible_strtod (const gchar *nptr,
gchar **endptr);
diff --git a/widgets/table/e-cell-date.c b/widgets/table/e-cell-date.c
index ce2355197b..64d9b8132b 100644
--- a/widgets/table/e-cell-date.c
+++ b/widgets/table/e-cell-date.c
@@ -43,8 +43,8 @@ ecd_get_text(ECellText *cell, ETableModel *model, int col, int row)
time_t nowdate = time(NULL);
time_t yesdate;
struct tm then, now, yesterday;
- char buf[26];
- char *temp, *ret_val;
+ char buf[100];
+ char *temp;
gboolean done = FALSE;
if (date == 0) {
@@ -55,7 +55,7 @@ ecd_get_text(ECellText *cell, ETableModel *model, int col, int row)
localtime_r (&nowdate, &now);
if (nowdate - date < 60 * 60 * 8 && nowdate > date) {
- e_strftime_fix_am_pm (buf, 26, _("%l:%M %p"), &then);
+ e_utf8_strftime_fix_am_pm (buf, 100, _("%l:%M %p"), &then);
done = TRUE;
}
@@ -63,7 +63,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) {
- e_strftime_fix_am_pm (buf, 26, _("Today %l:%M %p"), &then);
+ e_utf8_strftime_fix_am_pm (buf, 100, _("Today %l:%M %p"), &then);
done = TRUE;
}
}
@@ -73,15 +73,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) {
-#if 0
- if (nowdate - date < 60 * 60 * 12) {
- e_strftime_fix_am_pm (buf, 26, _("Late Yesterday %l:%M %p"), &then);
- } else {
-#endif
- e_strftime_fix_am_pm (buf, 26, _("Yesterday %l:%M %p"), &then);
-#if 0
- }
-#endif
+ e_utf8_strftime_fix_am_pm (buf, 100, _("Yesterday %l:%M %p"), &then);
done = TRUE;
}
}
@@ -93,7 +85,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) {
- e_strftime_fix_am_pm (buf, 26, _("%a %l:%M %p"), &then);
+ e_utf8_strftime_fix_am_pm (buf, 100, _("%a %l:%M %p"), &then);
done = TRUE;
break;
}
@@ -101,26 +93,17 @@ ecd_get_text(ECellText *cell, ETableModel *model, int col, int row)
}
if (!done) {
if (then.tm_year == now.tm_year) {
- e_strftime_fix_am_pm (buf, 26, _("%b %d %l:%M %p"), &then);
+ e_utf8_strftime_fix_am_pm (buf, 100, _("%b %d %l:%M %p"), &then);
} else {
- e_strftime_fix_am_pm (buf, 26, _("%b %d %Y"), &then);
+ e_utf8_strftime_fix_am_pm (buf, 100, _("%b %d %Y"), &then);
}
}
-#if 0
-#ifdef CTIME_R_THREE_ARGS
- ctime_r (&date, buf, 26);
-#else
- ctime_r (&date, buf);
-#endif
-#endif
temp = buf;
while ((temp = strstr (temp, " "))) {
memmove (temp, temp + 1, strlen (temp));
}
temp = e_strdup_strip (buf);
- ret_val = e_utf8_from_locale_string (temp);
- g_free (temp);
- return ret_val;
+ return temp;
}
static void