FIX: clone dateTime before changing timezone

approved
#1

FIX: clone dateTime before changing timezone

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 9b5cd8c..a4f8b8f 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
@@ -201,14 +201,13 @@
   }
 
   function _createDateTimeRange(dateTime, timezone) {
-    const startRange = dateTime.tz(timezone).format("LLL");
-    const separator = "→";
-    const endRange = dateTime
-      .add(24, "hours")
-      .tz(timezone)
-      .format("LLL");
-
-    return `${startRange} ${separator} ${endRange}`;
+    const dt = moment(dateTime).tz(timezone);
+
+    return [
+      dt.format("LLL"),
+      "→",
+      dt.add(24, "hours").format("LLL"),
+    ].join(" ");
   }
 
   function _generatePreviews(dateTime, displayedTimezone, options) {
@@ -222,7 +221,7 @@
       timezone: watchingUserTimezone,
       current: true,
       dateTime: options.time
-        ? dateTime.tz(watchingUserTimezone).format("LLL")
+        ? moment(dateTime).tz(watchingUserTimezone).format("LLL")
         : _createDateTimeRange(dateTime, watchingUserTimezone)
     });
 
@@ -249,7 +248,7 @@
         previewedTimezones.push({
           timezone,
           dateTime: options.time
-            ? dateTime.tz(timezone).format("LLL")
+            ? moment(dateTime).tz(timezone).format("LLL")
             : _createDateTimeRange(dateTime, timezone)
         });
       });
@@ -258,7 +257,7 @@
       previewedTimezones.push({
         timezone: "Etc/UTC",
         dateTime: options.time
-          ? dateTime.tz("Etc/UTC").format("LLL")
+          ? moment(dateTime).tz("Etc/UTC").format("LLL")
           : _createDateTimeRange(dateTime, "Etc/UTC")
       });
     }

GitHub sha: c131903e

#3

This commit has been mentioned on Discourse Meta. There might be relevant details there:

Approved #4