[epiphany] ephy-time-helpers: Respect user settings for display times
- From: Jan-Michael Brummer <jbrummer src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] ephy-time-helpers: Respect user settings for display times
- Date: Sun, 16 Dec 2018 18:59:58 +0000 (UTC)
commit d4ccb1032714f0cfc1434f4b4fd0f2472e213e1f
Author: Jan-Michael Brummer <jan brummer tabos org>
Date: Sun Dec 16 18:41:07 2018 +0100
ephy-time-helpers: Respect user settings for display times
Get current user display times settings (12h/24h) format and adjust strings accordingly.
Fixes: https://gitlab.gnome.org/GNOME/epiphany/issues/197
lib/ephy-time-helpers.c | 64 ++++++++++++++++++++++++++++++++++++++-----------
lib/meson.build | 1 +
meson.build | 1 +
3 files changed, 52 insertions(+), 14 deletions(-)
---
diff --git a/lib/ephy-time-helpers.c b/lib/ephy-time-helpers.c
index ff3147b86..3946112c2 100644
--- a/lib/ephy-time-helpers.c
+++ b/lib/ephy-time-helpers.c
@@ -27,9 +27,12 @@
#include <config.h>
#include <string.h>
+#include <gdesktop-enums.h>
+#include <gio/gio.h>
#include <glib/gi18n.h>
#include <glib.h>
+#include "ephy-settings.h"
#include "ephy-time-helpers.h"
/* Legal conversion specifiers, as specified in the C standard. */
@@ -210,6 +213,12 @@ ephy_time_helpers_utf_friendly_time (time_t date)
const char *format = NULL;
char *str = NULL;
gboolean done = FALSE;
+ GSettings *settings;
+ gboolean use_24;
+
+ settings = ephy_settings_get ("org.gnome.desktop.interface");
+
+ use_24 = g_settings_get_enum (settings, "clock-format") == G_DESKTOP_CLOCK_FORMAT_24H;
nowdate = time (NULL);
@@ -222,8 +231,14 @@ ephy_time_helpers_utf_friendly_time (time_t date)
if (then.tm_mday == now.tm_mday &&
then.tm_mon == now.tm_mon &&
then.tm_year == now.tm_year) {
- /* Translators: "friendly time" string for the current day, strftime format. like "Today 12∶34 am" */
- format = _("Today %I∶%M %p");
+
+ if (!use_24) {
+ /* Translators: "friendly time" string for the current day, strftime format. like "Today 12∶34 am" */
+ format = _("Today %I∶%M %p");
+ } else {
+ /* Translators: "friendly time" string for the current day, strftime format. like "Today 15∶34" */
+ format = _("Today %H∶%M");
+ }
done = TRUE;
}
@@ -233,10 +248,17 @@ ephy_time_helpers_utf_friendly_time (time_t date)
if (then.tm_mday == yesterday.tm_mday &&
then.tm_mon == yesterday.tm_mon &&
then.tm_year == yesterday.tm_year) {
- /* Translators: "friendly time" string for the previous day,
- * strftime format. e.g. "Yesterday 12∶34 am"
- */
- format = _("Yesterday %I∶%M %p");
+ if (!use_24) {
+ /* Translators: "friendly time" string for the previous day,
+ * strftime format. e.g. "Yesterday 12∶34 am"
+ */
+ format = _("Yesterday %I∶%M %p");
+ } else {
+ /* Translators: "friendly time" string for the previous day,
+ * strftime format. e.g. "Yesterday 15∶34"
+ */
+ format = _("Yesterday %H∶%M %p");
+ }
done = TRUE;
}
}
@@ -249,10 +271,17 @@ ephy_time_helpers_utf_friendly_time (time_t date)
if (then.tm_mday == yesterday.tm_mday &&
then.tm_mon == yesterday.tm_mon &&
then.tm_year == yesterday.tm_year) {
- /* Translators: "friendly time" string for a day in the current week,
- * strftime format. e.g. "Wed 12∶34 am"
- */
- format = _("%a %I∶%M %p");
+ if (!use_24) {
+ /* Translators: "friendly time" string for a day in the current week,
+ * strftime format. e.g. "Wed 12∶34 am"
+ */
+ format = _("%a %I∶%M %p");
+ } else {
+ /* Translators: "friendly time" string for a day in the current week,
+ * strftime format. e.g. "Wed 15∶34"
+ */
+ format = _("%a %H∶%M");
+ }
done = TRUE;
break;
}
@@ -261,10 +290,17 @@ ephy_time_helpers_utf_friendly_time (time_t date)
if (!done) {
if (then.tm_year == now.tm_year) {
- /* Translators: "friendly time" string for a day in the current year,
- * strftime format. e.g. "Feb 12 12∶34 am"
- */
- format = _("%b %d %I∶%M %p");
+ if (!use_24) {
+ /* Translators: "friendly time" string for a day in the current year,
+ * strftime format. e.g. "Feb 12 12∶34 am"
+ */
+ format = _("%b %d %I∶%M %p");
+ } else {
+ /* Translators: "friendly time" string for a day in the current year,
+ * strftime format. e.g. "Feb 12 15∶34"
+ */
+ format = _("%b %d %H∶%M");
+ }
} else {
/* Translators: "friendly time" string for a day in a different year,
* strftime format. e.g. "Feb 12 1997"
diff --git a/lib/meson.build b/lib/meson.build
index 866b26c4d..be5af33ef 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -60,6 +60,7 @@ libephymisc_deps = [
gio_dep,
gio_unix_dep,
glib_dep,
+ gsettings_desktop_schemas,
gtk_dep,
icu_uc_dep,
json_glib_dep,
diff --git a/meson.build b/meson.build
index a6e5ea709..903708da5 100644
--- a/meson.build
+++ b/meson.build
@@ -79,6 +79,7 @@ gdk_pixbuf_dep = dependency('gdk-pixbuf-2.0', version: '>= 2.36.5')
gio_dep = dependency('gio-2.0', version: glib_requirement)
gio_unix_dep = dependency('gio-unix-2.0', version: glib_requirement)
glib_dep = dependency('glib-2.0', version: glib_requirement)
+gsettings_desktop_schemas = dependency('gsettings-desktop-schemas')
gtk_dep = dependency('gtk+-3.0', version: gtk_requirement)
gtk_unix_print_dep = dependency('gtk+-unix-print-3.0', version: gtk_requirement)
hogweed_dep = dependency('hogweed', version: nettle_requirement)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]