FIX: improves DST support of dates when recurrence is used (#7297)

FIX: improves DST support of dates when recurrence is used (#7297)

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 daacf30..9b5cd8c 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
@@ -185,8 +185,19 @@
     const type = parts[1];
     const diff = moment().diff(dateTime, type);
     const add = Math.ceil(diff + count);
+    const wasDST = moment(dateTime.format()).isDST();
+    let dateTimeWithRecurrence = dateTime.add(add, type);
+    const isDST = moment(dateTimeWithRecurrence.format()).isDST();
 
-    return dateTime.add(add, type);
+    if (!wasDST && isDST) {
+      dateTimeWithRecurrence.subtract(1, "hour");
+    }
+
+    if (wasDST && !isDST) {
+      dateTimeWithRecurrence.add(1, "hour");
+    }
+
+    return dateTimeWithRecurrence;
   }
 
   function _createDateTimeRange(dateTime, timezone) {

GitHub sha: d81f3ee2

1 Like