[gnome-shell] dateMenu: Format weather forecast times without AM/PM



commit 83f224e08b0a016f995610dbcc3389ee4b374dbf
Author: Philip Chimento <philip endlessm com>
Date:   Tue Nov 19 13:15:34 2019 -0800

    dateMenu: Format weather forecast times without AM/PM
    
    If the clock is set to 12h, the AM/PM in the weather forecast times
    should be clear from the context, because they are the immediately
    following hours. This makes it less likely that the times will be
    ellipsized (in which case the AM/PM wouldn't be shown anyway.)
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/835

 js/misc/util.js   | 10 +++++++++-
 js/ui/dateMenu.js |  1 +
 2 files changed, 10 insertions(+), 1 deletion(-)
---
diff --git a/js/misc/util.js b/js/misc/util.js
index b7ee017982..b2c46a79a0 100644
--- a/js/misc/util.js
+++ b/js/misc/util.js
@@ -217,7 +217,10 @@ function formatTime(time, params) {
         _desktopSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.interface' });
     let clockFormat = _desktopSettings.get_string('clock-format');
 
-    params = Params.parse(params, { timeOnly: false });
+    params = Params.parse(params, {
+        timeOnly: false,
+        ampm: true,
+    });
 
     if (clockFormat == '24h') {
         // Show only the time if date is on today
@@ -279,6 +282,11 @@ function formatTime(time, params) {
             format = N_("%B %-d %Y, %l\u2236%M %p");
     }
 
+    // Time in short 12h format, without the equivalent of "AM" or "PM"; used
+    // when it is clear from the context
+    if (!params.ampm)
+        format = format.replace(/\s*%p/g, '');
+
     let formattedTime = date.format(Shell.util_translate_time_string(format));
     // prepend LTR-mark to colon/ratio to force a text direction on times
     return formattedTime.replace(/([:\u2236])/g, '\u200e$1');
diff --git a/js/ui/dateMenu.js b/js/ui/dateMenu.js
index e506dbc49e..51413c5660 100644
--- a/js/ui/dateMenu.js
+++ b/js/ui/dateMenu.js
@@ -336,6 +336,7 @@ class WeatherSection extends St.Button {
             let [ok_, timestamp] = fc.get_value_update();
             let timeStr = Util.formatTime(new Date(timestamp * 1000), {
                 timeOnly: true,
+                ampm: false,
             });
 
             let icon = new St.Icon({ style_class: 'weather-forecast-icon',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]