FIX: better identifier and uses real dates for grouping

FIX: better identifier and uses real dates for grouping

diff --git a/assets/javascripts/initializers/discourse-calendar.js.es6 b/assets/javascripts/initializers/discourse-calendar.js.es6
index 186f8df..af5993a 100644
--- a/assets/javascripts/initializers/discourse-calendar.js.es6
+++ b/assets/javascripts/initializers/discourse-calendar.js.es6
@@ -443,18 +443,16 @@ function initializeDiscourseCalendar(api) {
       const minDate = moment(groupedEvent.from)
         .utc()
         .startOf("day")
-        .subtract(12, "hours")
         .toISOString();
-      const maxdate = moment(groupedEvent.to || groupedEvent.from)
+      const maxDate = moment(groupedEvent.to || groupedEvent.from)
         .utc()
         .endOf("day")
-        .add(12, "hours")
         .toISOString();
 
-      const identifier = `${minDate}-${maxdate}`;
+      const identifier = `${minDate}-${maxDate}`;
       formatedGroupedEvents[identifier] = formatedGroupedEvents[identifier] || {
-        from: groupedEvent.from,
-        to: groupedEvent.to,
+        from: minDate,
+        to: maxDate || minDate,
         localEvents: {}
       };
 
diff --git a/plugin.rb b/plugin.rb
index f94ca4c..7456a8a 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -319,7 +319,7 @@ after_initialize do
           post_url: Post.url('-', event.topic_id, event.post_number)
         }
       else
-        identifier = "#{event.region.split("_").first}-#{event.description}-#{event.start_date.strftime("%W")}"
+        identifier = "#{event.region.split("_").first}-#{event.start_date.strftime("%W")}-#{(event.end_date || event.start_date).strftime("%W")}"
 
         if grouped_events[identifier]
           grouped_events[identifier][:to] = event.start_date
@@ -328,7 +328,8 @@ after_initialize do
             type: :grouped,
             name: event.description,
             from: event.start_date,
-            usernames: []
+            usernames: [],
+            identifier: identifier
           }
         end
 

GitHub sha: f5ffee3e

1 Like