[gnome-shell] Improve 12/24 clock detection



commit 046e0609abff6ad3ced0120e997fba7469e62e83
Author: Dirk-Jan C. Binnema <djcb djcbsoftware nl>
Date:   Sat Feb 27 10:29:13 2010 +0200

    Improve 12/24 clock detection
    
    The current check looks at whether there was some am/pm suffix in the
    localized time; however in some cases (locales) that does not seem to
    work. this version instead checks whether the localized versions of 05:00 and
    17:00 start with the same two digits; if not, it's probably a 24h clock.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=603488

 js/ui/panel.js |   25 ++++++++++++++++---------
 1 files changed, 16 insertions(+), 9 deletions(-)
---
diff --git a/js/ui/panel.js b/js/ui/panel.js
index d4f3430..6cce4c6 100644
--- a/js/ui/panel.js
+++ b/js/ui/panel.js
@@ -616,15 +616,22 @@ Panel.prototype = {
             displayDate.setMinutes(displayDate.getMinutes() + 1);
             msecRemaining += 60000;
         }
-	/* If there is no am or pm, time format is 24h */
-	let isTime24h = displayDate.toLocaleFormat("x%p") == "x";
-	if (isTime24h) {
-	  /* Translators: This is the time format used in 24-hour mode. */
-	  this._clock.set_text(displayDate.toLocaleFormat(_("%a %R")));
-	} else {
-	  /* Translators: This is a time format used for AM/PM. */
-	  this._clock.set_text(displayDate.toLocaleFormat(_("%a %l:%M %p")));
-	}
+
+        // if the locale representations of 05:00 and 17:00 do not
+        // start with the same 2 digits, it must be a 24h clock
+        let fiveAm = new Date();
+        fiveAm.setHours(5);
+        let fivePm = new Date();
+        fivePm.setHours(17);
+        let isTime24h = fiveAm.toLocaleFormat("%X").substr(0,2) !=
+                        fivePm.toLocaleFormat("%X").substr(0,2);
+        if (isTime24h) {
+            /* Translators: This is the time format used in 24-hour mode. */
+            this._clock.set_text(displayDate.toLocaleFormat(_("%a %R")));
+        } else {
+            /* Translators: This is a time format used for AM/PM. */
+            this._clock.set_text(displayDate.toLocaleFormat(_("%a %l:%M %p")));
+        }
         Mainloop.timeout_add(msecRemaining, Lang.bind(this, this._updateClock));
         return false;
     },



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