FIX: local date trim when no time available (#14525)

FIX: local date trim when no time available (#14525)

When there is a blank space in the end of date, moment is returning a different value:

  console.log(moment.tz("2021-09-09 ", "Australia/Sydney").toISOString());
  // 2021-09-09T00:00:00.000Z
  console.log(moment.tz("2021-09-09", "Australia/Sydney").toISOString());
  // 2021-09-08T14:00:00.000Z
diff --git a/plugins/discourse-local-dates/assets/javascripts/initializers/discourse-local-dates.js.es6 b/plugins/discourse-local-dates/assets/javascripts/initializers/discourse-local-dates.js.es6
index 19a9be3..2737417 100644
--- a/plugins/discourse-local-dates/assets/javascripts/initializers/discourse-local-dates.js.es6
+++ b/plugins/discourse-local-dates/assets/javascripts/initializers/discourse-local-dates.js.es6
@@ -182,7 +182,7 @@ function _downloadCalendarNode(element) {
     "data-starts-at",
     moment
       .tz(
-        `${startDataset.date} ${startDataset.time || ""}`,
+        `${startDataset.date} ${startDataset.time || ""}`.trim(),
         startDataset.timezone
       )
       .toISOString()
@@ -191,7 +191,10 @@ function _downloadCalendarNode(element) {
     node.setAttribute(
       "data-ends-at",
       moment
-        .tz(`${endDataset.date} ${endDataset.time || ""}`, endDataset.timezone)
+        .tz(
+          `${endDataset.date} ${endDataset.time || ""}`.trim(),
+          endDataset.timezone
+        )
         .toISOString()
     );
   }

GitHub sha: 4285706d97108981962c68e4896a5a7954cc6d5b

This commit appears in #14525 which was approved by tgxworld. It was merged by lis2.