summaryrefslogtreecommitdiff
path: root/src/util.cpp
diff options
context:
space:
mode:
authorrbuj <[email protected]>2019-04-19 21:01:10 +0200
committerraveit65 <[email protected]>2019-04-29 15:07:26 +0200
commitc09e5228537e4bcf5c9a074c696b698ff8ead1a5 (patch)
tree4d7c5ed14dee43c2a517a294ebe74724ffddc29d /src/util.cpp
parentfc1f63b1c04cb6101f3a780e104a7f295c4d307a (diff)
downloadmate-system-monitor-c09e5228537e4bcf5c9a074c696b698ff8ead1a5.tar.bz2
mate-system-monitor-c09e5228537e4bcf5c9a074c696b698ff8ead1a5.tar.xz
Use g_date_time_format instead of filter_date
https://developer.gnome.org/glib/stable/glib-GDateTime.html#g-date-time-format
Diffstat (limited to 'src/util.cpp')
-rw-r--r--src/util.cpp35
1 files changed, 31 insertions, 4 deletions
diff --git a/src/util.cpp b/src/util.cpp
index 14c559d..8548249 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -1,5 +1,6 @@
#include <config.h>
+#include <glib/gprintf.h>
#include <glib/gi18n.h>
#include <glib.h>
#include <gtk/gtk.h>
@@ -14,10 +15,36 @@
#include "util.h"
#include "procman.h"
-extern "C" {
-#include "e_date.h"
-}
+gchar *
+procman_format_date_for_display(time_t time_raw)
+{
+ gchar *result = NULL;
+ const char *format;
+ GDateTime *date_time, *today;
+ GTimeSpan date_age;
+
+ date_time = g_date_time_new_from_unix_local (time_raw);
+ today = g_date_time_new_now_local ();
+
+ date_age = g_date_time_difference (today, date_time);
+ if (date_age < G_TIME_SPAN_DAY) {
+ format = _("Today %l:%M %p");
+ } else if (date_age < 2 * G_TIME_SPAN_DAY) {
+ format = _("Yesterday %l:%M %p");
+ } else if (date_age < 7 * G_TIME_SPAN_DAY) {
+ format = _("%a %l:%M %p");
+ } else if (g_date_time_get_year (date_time) == g_date_time_get_year (today)) {
+ format = _("%b %d %l:%M %p");
+ } else {
+ format = _("%b %d %Y");
+ }
+
+ g_date_time_unref (today);
+ result = g_date_time_format (date_time, format);
+ g_date_time_unref (date_time);
+ return result;
+}
const char*
format_process_state(guint state)
@@ -518,7 +545,7 @@ namespace procman
g_value_unset(&value);
- char *str = procman_format_date_for_display(time);
+ gchar *str = procman_format_date_for_display(time);
g_object_set(renderer, "text", str, NULL);
g_free(str);
}