From 9bac0d09af4a914f22755f31798f2f88e3e8f833 Mon Sep 17 00:00:00 2001 From: dev <69985420+dev-dev-dev-dev-dev-dev-dev-dev@users.noreply.github.com> Date: Sat, 8 Jul 2023 03:57:16 -0700 Subject: [PATCH] Added "relative-timestamps" config to switch between "25 minutes ago" and "2023-06-25T20:05:27-07" (#286) Co-authored-by: Erik Reider <35975961+ErikReider@users.noreply.github.com> --- man/swaync.5.scd | 12 +++++++++--- src/config.json.in | 1 + src/configModel/configModel.vala | 6 ++++++ src/configSchema.json | 5 +++++ src/notification/notification.vala | 13 +++++++++++-- 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/man/swaync.5.scd b/man/swaync.5.scd index ff92f3e..142fe12 100644 --- a/man/swaync.5.scd +++ b/man/swaync.5.scd @@ -124,16 +124,22 @@ config file to be able to detect config errors default: true ++ description: Whether the control center should expand vertically to fill the screen +*relative-timestamps* ++ + type: bool ++ + default: true ++ + description: Display notification timestamps relative to now e.g. \"26 minutes ago\". ++ + If false, a local iso8601-formatted absolute timestamp is displayed. + *control-center-height* ++ type: integer ++ default: 500 ++ - description: The control centers height in pixels. - This setting is ignored when _fit-to-screen_ it set to "true" + description: The control center height in pixels ++ + This setting is ignored when _fit-to-screen_ is set to "true". *control-center-width* ++ type: integer ++ default: 500 ++ - description: The control centers width in pixels + description: The control center width in pixels *notification-visibility* ++ type: object ++ diff --git a/src/config.json.in b/src/config.json.in index 99fb9cb..da2c46c 100644 --- a/src/config.json.in +++ b/src/config.json.in @@ -19,6 +19,7 @@ "timeout-low": 5, "timeout-critical": 0, "fit-to-screen": true, + "relative-timestamps": true, "control-center-width": 500, "control-center-height": 600, "notification-window-width": 500, diff --git a/src/configModel/configModel.vala b/src/configModel/configModel.vala index 8e96790..b74ddce 100644 --- a/src/configModel/configModel.vala +++ b/src/configModel/configModel.vala @@ -523,6 +523,12 @@ namespace SwayNotificationCenter { /** Whether to expand the notification center across both edges of the screen */ public bool fit_to_screen { get; set; default = true; } + /** + * Display notification timestamp relative to now e.g. "26 minutes ago". + * If false, a local iso8601-formatted absolute timestamp is displayed. + */ + public bool relative_timestamps { get; set; default = true; } + /** * Notification center's height, in pixels. * Set `fit_to_screen` to true to ignore the height setting. diff --git a/src/configSchema.json b/src/configSchema.json index 448a9cc..bb35e40 100644 --- a/src/configSchema.json +++ b/src/configSchema.json @@ -128,6 +128,11 @@ "description": "If the control center should expand to both edges of the screen", "default": true }, + "relative-timestamps": { + "type": "boolean", + "description": "Display notification timestamps relative to now e.g. \"26 minutes ago\". If false, a local iso8601-formatted absolute timestamp is displayed.", + "default": true + }, "control-center-height": { "type": "integer", "description": "Height of the control center in pixels. Ignored when 'fit-to-screen' is set to 'true'", diff --git a/src/notification/notification.vala b/src/notification/notification.vala index b5b2db8..b023045 100644 --- a/src/notification/notification.vala +++ b/src/notification/notification.vala @@ -556,10 +556,14 @@ namespace SwayNotificationCenter { } public void set_time () { - this.time.set_text (get_readable_time ()); + if (ConfigModel.instance.relative_timestamps) { + this.time.set_text (get_relative_time ()); + } else { + this.time.set_text (get_iso8601_time ()); + } } - private string get_readable_time () { + private string get_relative_time () { string value = ""; double diff = (get_real_time () * 0.000001) - param.time; @@ -590,6 +594,11 @@ namespace SwayNotificationCenter { return value; } + private string get_iso8601_time () { + var dtime = new DateTime.from_unix_local (param.time); + return dtime.format_iso8601 (); + } + public void close_notification (bool is_timeout = false) { remove_noti_timeout (); this.revealer.set_reveal_child (false);