FIX: compares timezones on utc offset and not name (#6672)

FIX: compares timezones on utc offset and not name (#6672)

From 75dac3132359d3afca03d79c412536437e4a4aba Mon Sep 17 00:00:00 2001
From: Joffrey JAFFEUX <j.jaffeux@gmail.com>
Date: Tue, 27 Nov 2018 12:36:19 +0100
Subject: [PATCH] FIX: compares timezones on utc offset and not name (#6672)


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 d9ff154..6d71eec 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
@@ -121,7 +121,9 @@
     };
 
     const _applyFormatting = (dateTime, displayedTimezone, options) => {
-      const sameTimezone = displayedTimezone === moment.tz.guess();
+      const sameTimezone =
+        moment.tz(displayedTimezone).utcOffset() ===
+        moment.tz(moment.tz.guess()).utcOffset();
       const inCalendarRange = dateTime.isBetween(
         moment().subtract(2, "days"),
         moment().add(2, "days")
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 87f12d9..df2e73d 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
@@ -97,6 +97,17 @@ test("default format - no time specified", assert => {
       "it appends creator timezone if watching user timezone is different"
     );
   });
+
+  freezeDateAndZone(advance(1), "Europe/Vienna", () => {
+    html = generateHTML({ date: advance(3) });
+    transformed = $(html).applyLocalDates();
+
+    assert.equal(
+      transformed.text().trim(),
+      "June 23, 2018",
+      "it doesn’t append timezone if different but with the same utc offset"
+    );
+  });
 });
 
 test("today", assert => {

GitHub

1 Like