FIX: removes country from timezone indicator (#6677)

FIX: removes country from timezone indicator (#6677)

From d461794fbfcc298af49872a26da07bbcfce02db1 Mon Sep 17 00:00:00 2001
From: Joffrey JAFFEUX <j.jaffeux@gmail.com>
Date: Tue, 27 Nov 2018 11:52:02 +0100
Subject: [PATCH] FIX: removes country from timezone indicator (#6677)


diff --git a/plugins/discourse-local-dates/assets/javascripts/discourse-local-dates.js.no-module.es6 b/plugins/discourse-local-dates/assets/javascripts/discourse-local-dates.js.no-module.es6
index c1986dd..d9ff154 100644
--- a/plugins/discourse-local-dates/assets/javascripts/discourse-local-dates.js.no-module.es6
+++ b/plugins/discourse-local-dates/assets/javascripts/discourse-local-dates.js.no-module.es6
@@ -84,6 +84,11 @@
         .replace("Etc/", "")
         .split("/");
 
+    const _zoneWithoutPrefix = timezone => {
+      const parts = _formatTimezone(timezone);
+      return parts[1] || parts[0];
+    };
+
     const _applyZoneToDateTime = (dateTime, timezone) => {
       return moment.tz(dateTime, timezone).utc();
     };
@@ -132,9 +137,7 @@
         } else {
           dateTime = dateTime.format(options.format);
           dateTime = dateTime.replace("TZ", "");
-          dateTime = `${dateTime} (${_formatTimezone(displayedTimezone).join(
-            ": "
-          )})`;
+          dateTime = `${dateTime} (${_zoneWithoutPrefix(displayedTimezone)})`;
         }
       } else {
         if (options.time) {
@@ -142,9 +145,7 @@
 
           if (options.displayedTimezone && !sameTimezone) {
             dateTime = dateTime.replace("TZ", "");
-            dateTime = `${dateTime} (${_formatTimezone(displayedTimezone).join(
-              ": "
-            )})`;
+            dateTime = `${dateTime} (${_zoneWithoutPrefix(displayedTimezone)})`;
           } else {
             dateTime = dateTime.replace(
               "TZ",
@@ -156,13 +157,11 @@
 
           if (!sameTimezone) {
             dateTime = dateTime.replace("TZ", "");
-            dateTime = `${dateTime} (${_formatTimezone(displayedTimezone).join(
-              ": "
-            )})`;
+            dateTime = `${dateTime} (${_zoneWithoutPrefix(displayedTimezone)})`;
           } else {
             dateTime = dateTime.replace(
               "TZ",
-              _formatTimezone(displayedTimezone).join(": ")
+              _zoneWithoutPrefix(displayedTimezone)
             );
           }
         }
@@ -223,14 +222,12 @@
     const _generateTextPreview = previews => {
       return previews
         .map(preview => {
-          const timezoneParts = _formatTimezone(preview.timezone);
+          const formatedZone = _zoneWithoutPrefix(preview.timezone);
 
           if (preview.dateTime.match(/TZ/)) {
-            return preview.dateTime.replace(/TZ/, timezoneParts.join(": "));
+            return preview.dateTime.replace(/TZ/, formatedZone);
           } else {
-            let output = timezoneParts[0];
-            if (timezoneParts[1]) output += ` (${timezoneParts[1]})`;
-            return (output += ` ${preview.dateTime}`);
+            return `${formatedZone} ${preview.dateTime}`;
           }
         })
         .join(", ");
@@ -251,9 +248,7 @@
 
         if (preview.current) $template.addClass("current");
 
-        $template
-          .find(".timezone")
-          .text(_formatTimezone(preview.timezone).join(": "));
+        $template.find(".timezone").text(_zoneWithoutPrefix(preview.timezone));
         $template.find(".date-time").text(preview.dateTime);
         $htmlTooltip.append($template);
       });
diff --git a/plugins/discourse-local-dates/test/javascripts/acceptance/local-dates-test.js.es6 b/plugins/discourse-local-dates/test/javascripts/acceptance/local-dates-test.js.es6
index ceae0ca..87f12d9 100644
--- a/plugins/discourse-local-dates/test/javascripts/acceptance/local-dates-test.js.es6
+++ b/plugins/discourse-local-dates/test/javascripts/acceptance/local-dates-test.js.es6
@@ -16,7 +16,7 @@ acceptance("Local Dates", {
 
 const DEFAULT_DATE = "2018-06-20";
 const DEFAULT_ZONE = "Europe/Paris";
-const DEFAULT_ZONE_FORMATED = DEFAULT_ZONE.split("/").join(": ");
+const DEFAULT_ZONE_FORMATED = DEFAULT_ZONE.split("/")[1];
 
 function advance(count, unit = "days") {
   return moment(DEFAULT_DATE)
@@ -237,7 +237,7 @@ test("displayedTimezone", assert => {
 
   assert.equal(
     transformed.text().trim(),
-    "June 23, 2018 9:00 AM (America: Chicago)",
+    "June 23, 2018 9:00 AM (Chicago)",
     "it displays timezone when different from watching user"
   );
 
@@ -279,7 +279,7 @@ test("displayedTimezone", assert => {
 
   assert.equal(
     transformed.text().trim(),
-    "June 20, 2018 (America: Chicago)",
+    "June 20, 2018 (Chicago)",
     "it uses timezone when displayedTimezone is not set"
   );
 
@@ -300,7 +300,7 @@ test("displayedTimezone", assert => {
 
   assert.equal(
     transformed.text().trim(),
-    "June 20, 2018 (Pacific: Auckland)",
+    "June 20, 2018 (Auckland)",
     "it uses displayedTimezone over timezone"
   );
 });

GitHub

2 Likes