[evolution] Bug 610741 - Allow changing the abbreviated date (%ad) date format
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] Bug 610741 - Allow changing the abbreviated date (%ad) date format
- Date: Fri, 19 Oct 2018 10:53:04 +0000 (UTC)
commit a4fbe506aeb67c720e8aaab661ff4638e0f030f3
Author: Milan Crha <mcrha redhat com>
Date: Fri Oct 19 12:53:35 2018 +0200
Bug 610741 - Allow changing the abbreviated date (%ad) date format
Closes https://bugzilla.gnome.org/show_bug.cgi?id=610741
src/e-util/e-datetime-format.c | 28 +++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)
---
diff --git a/src/e-util/e-datetime-format.c b/src/e-util/e-datetime-format.c
index 185c37a8f7..9f8a06d6f1 100644
--- a/src/e-util/e-datetime-format.c
+++ b/src/e-util/e-datetime-format.c
@@ -180,10 +180,11 @@ set_format_internal (const gchar *key,
static gchar *
format_relative_date (time_t tvalue,
time_t ttoday,
+ const gchar *prefer_date_fmt,
const struct tm *value,
const struct tm *today)
{
- gchar *res = g_strdup (get_default_format (DTFormatKindDate, NULL));
+ gchar *res = g_strdup (prefer_date_fmt ? prefer_date_fmt : get_default_format (DTFormatKindDate,
NULL));
GDate now, val;
gint diff;
@@ -303,9 +304,10 @@ format_internal (const gchar *key,
if (fmt[i + 1] == '%') {
i++;
} else if (fmt[i + 1] == 'a' && fmt[i + 2] == 'd' && (fmt[i + 3] == 0 ||
!g_ascii_isalpha (fmt[i + 3]))) {
- gchar *ad;
+ gchar *ad, *prefer_date_fmt = NULL;
- /* "%ad" for abbreviated date */
+ /* "%ad" for abbreviated date; it can be optionally extended
+ with preferred date format in [], like this: "%ad[%Y-%m-%d]" */
if (!use_fmt) {
use_fmt = g_string_new ("");
@@ -317,12 +319,28 @@ format_internal (const gchar *key,
last = i + 3;
i += 2;
- ad = format_relative_date (tvalue, ttoday, &value, &today);
+ if (fmt[i + 1] == '[' && fmt[i + 2] != ']') {
+ const gchar *end;
+
+ end = strchr (fmt + i + 1, ']');
+ if (end) {
+ gint len = end - fmt - i - 1;
+
+ prefer_date_fmt = g_strndup (fmt + i + 2, len - 1);
+
+ /* Include the ending ']' */
+ last += len + 1;
+ i += len + 1;
+ }
+ }
+
+ ad = format_relative_date (tvalue, ttoday, prefer_date_fmt, &value, &today);
if (ad)
g_string_append (use_fmt, ad);
- else if (g_ascii_isspace (fmt[i + 3]))
+ else if (g_ascii_isspace (fmt[i + 1]))
i++;
+ g_free (prefer_date_fmt);
g_free (ad);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]