[polari] chatView: Only use 12-hour format when supported by the locale



commit acbcf0f344f7914331936123672520808deb9ceb
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Apr 3 15:31:51 2014 +0200

    chatView: Only use 12-hour format when supported by the locale
    
    It is a bit odd to request AM/PM format when the locale selected
    by LC_TIME lacks the concept. The GNOME desktop ignores the format
    setting in that case and assumes 24-hour format, let's do the same
    for consistency.

 src/chatView.js |  116 ++++++++++++++++++++++++++----------------------------
 1 files changed, 56 insertions(+), 60 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index 52e9860..af9405c 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -555,66 +555,62 @@ const ChatView = new Lang.Class({
         let format;
         let desktopSettings = new Gio.Settings({ schema: 'org.gnome.desktop.interface' });
         let clockFormat = desktopSettings.get_string('clock-format');
-
-        switch (clockFormat) {
-            case '24h':
-                if(daysAgo < 1) { // today
-                    /* Translators: Time in 24h format */
-                    format = _("%H\u2236%M");
-                } else if(daysAgo <2) { // yesterday
-                    /* Translators: this is the word "Yesterday" followed by a
-                     time string in 24h format. i.e. "Yesterday, 14:30" */
-                    // xgettext:no-c-format
-                    format = _("Yesterday, %H\u2236%M");
-                } else if (daysAgo < 7) { // this week
-                    /* Translators: this is the week day name followed by a time
-                     string in 24h format. i.e. "Monday, 14:30" */
-                    // xgettext:no-c-format
-                    format = _("%A, %H\u2236%M");
-                } else if (date.get_year() == now.get_year()) { // this year
-                    /* Translators: this is the month name and day number
-                     followed by a time string in 24h format.
-                     i.e. "May 25, 14:30" */
-                    // xgettext:no-c-format
-                    format = _("%B %d, %H\u2236%M");
-                } else { // before this year
-                    /* Translators: this is the month name, day number, year
-                     number followed by a time string in 24h format.
-                     i.e. "May 25 2012, 14:30" */
-                    // xgettext:no-c-format
-                    format = _("%B %d %Y, %H\u2236%M");
-                }
-                break;
-        default:
-            // explicit fall-through
-            case '12h':
-                if(daysAgo < 1) { // today
-                    /* Translators: Time in 12h format */
-                    format = _("%l\u2236%M %p");
-                } else if(daysAgo <2) { // yesterday
-                    /* Translators: this is the word "Yesterday" followed by a
-                     time string in 12h format. i.e. "Yesterday, 2:30 pm" */
-                    // xgettext:no-c-format
-                    format = _("Yesterday, %l\u2236%M %p");
-                } else if (daysAgo < 7) { // this week
-                    /* Translators: this is the week day name followed by a time
-                     string in 12h format. i.e. "Monday, 2:30 pm" */
-                    // xgettext:no-c-format
-                    format = _("%A, %l\u2236%M %p");
-                } else if (date.get_year() == now.get_year()) { // this year
-                    /* Translators: this is the month name and day number
-                     followed by a time string in 12h format.
-                     i.e. "May 25, 2:30 pm" */
-                    // xgettext:no-c-format
-                    format = _("%B %d, %l\u2236%M %p");
-                } else { // before this year
-                    /* Translators: this is the month name, day number, year
-                     number followed by a time string in 12h format.
-                     i.e. "May 25 2012, 2:30 pm"*/
-                    // xgettext:no-c-format
-                    format = _("%B %d %Y, %l\u2236%M %p");
-                }
-                break;
+        let hasAmPm = date.format('%p') != '';
+
+        if (clockFormat == '24h' || !hasAmPm) {
+            if(daysAgo < 1) { // today
+                /* Translators: Time in 24h format */
+                format = _("%H\u2236%M");
+            } else if(daysAgo <2) { // yesterday
+                /* Translators: this is the word "Yesterday" followed by a
+                 time string in 24h format. i.e. "Yesterday, 14:30" */
+                // xgettext:no-c-format
+                format = _("Yesterday, %H\u2236%M");
+            } else if (daysAgo < 7) { // this week
+                /* Translators: this is the week day name followed by a time
+                 string in 24h format. i.e. "Monday, 14:30" */
+                // xgettext:no-c-format
+                format = _("%A, %H\u2236%M");
+            } else if (date.get_year() == now.get_year()) { // this year
+                /* Translators: this is the month name and day number
+                 followed by a time string in 24h format.
+                 i.e. "May 25, 14:30" */
+                // xgettext:no-c-format
+                format = _("%B %d, %H\u2236%M");
+            } else { // before this year
+                /* Translators: this is the month name, day number, year
+                 number followed by a time string in 24h format.
+                 i.e. "May 25 2012, 14:30" */
+                // xgettext:no-c-format
+                format = _("%B %d %Y, %H\u2236%M");
+            }
+        } else {
+            if(daysAgo < 1) { // today
+                /* Translators: Time in 12h format */
+                format = _("%l\u2236%M %p");
+            } else if(daysAgo <2) { // yesterday
+                /* Translators: this is the word "Yesterday" followed by a
+                 time string in 12h format. i.e. "Yesterday, 2:30 pm" */
+                // xgettext:no-c-format
+                format = _("Yesterday, %l\u2236%M %p");
+            } else if (daysAgo < 7) { // this week
+                /* Translators: this is the week day name followed by a time
+                 string in 12h format. i.e. "Monday, 2:30 pm" */
+                // xgettext:no-c-format
+                format = _("%A, %l\u2236%M %p");
+            } else if (date.get_year() == now.get_year()) { // this year
+                /* Translators: this is the month name and day number
+                 followed by a time string in 12h format.
+                 i.e. "May 25, 2:30 pm" */
+                // xgettext:no-c-format
+                format = _("%B %d, %l\u2236%M %p");
+            } else { // before this year
+                /* Translators: this is the month name, day number, year
+                 number followed by a time string in 12h format.
+                 i.e. "May 25 2012, 2:30 pm"*/
+                // xgettext:no-c-format
+                format = _("%B %d %Y, %l\u2236%M %p");
+            }
         }
 
         return date.format(format);


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