Skip to content

A platform for community discussion. Free, open, simple.

FIX: Keep the dates of an expired recurring event (#44089)

Régis Hanola660cd1af635
diff --git a/plugins/discourse-events/app/models/discourse_events/events/event.rb b/plugins/discourse-events/app/models/discourse_events/events/event.rb
index d99aed8ca24..af203bc1435 100644
--- a/plugins/discourse-events/app/models/discourse_events/events/event.rb
+++ b/plugins/discourse-events/app/models/discourse_events/events/event.rb
@@ -164,10 +164,7 @@ module DiscourseEvents
bump = parsed_reminders.find { |reminder| reminder[:type] == BUMP_TOPIC_REMINDER }
return if bump.nil?
- bump_from = starts_at
- return if bump_from.nil?
-
- date = bump_from - Event.reminder_offset(bump)
+ date = starts_at - Event.reminder_offset(bump)
Jobs.enqueue(:discourse_post_event_bump_topic, topic_id: post.topic_id, date: date.iso8601)
end
@@ -206,7 +203,6 @@ module DiscourseEvents
def expired?
return recurrence_expired? if recurring?
- return true if starts_at.nil?
(ends_at || starts_at.end_of_day) <= Time.now
end
@@ -214,8 +210,6 @@ module DiscourseEvents
# model: joining opens EARLY_ACCESS_MINUTES before the start and, when the
# event has an end time, closes GRACE_PERIOD_MINUTES after it.
def currently_within_event_timeframe?
- return false if starts_at.nil?
-
now = Time.zone.now
if all_day
@@ -229,12 +223,10 @@ module DiscourseEvents
end
def starts_at
- return nil if recurring? && recurrence_expired?
current_event_date&.starts_at || original_starts_at
end
def ends_at
- return nil if recurring? && recurrence_expired?
current_event_date&.ends_at || original_ends_at
end
@@ -248,7 +240,6 @@ module DiscourseEvents
end
def on_going_event_invitees
- return [] if starts_at.nil? # Can't determine ongoing status without start time
if !ends_at && starts_at < Time.now && (!all_day || starts_at.end_of_day <= Time.now)
return []
end
@@ -363,7 +354,7 @@ module DiscourseEvents
end
def create_notification!(user, post, predefined_attendance: false)
- return if post.event.starts_at.nil? || post.event.starts_at < Time.current
+ return if post.event.starts_at < Time.current
return if !Guardian.new(user).can_see?(post)
message =
@@ -390,7 +381,7 @@ module DiscourseEvents
end
def ongoing?
- return false if closed || expired? || starts_at.nil?
+ return false if closed || expired?
finishes_at = ends_at || starts_at.end_of_day
(starts_at..finishes_at).cover?(Time.now)
end
diff --git a/plugins/discourse-events/app/serializers/discourse_events/events/basic_event_serializer.rb b/plugins/discourse-events/app/serializers/discourse_events/events/basic_event_serializer.rb
index f6497e2ed30..5d098dc2e22 100644
--- a/plugins/discourse-events/app/serializers/discourse_events/events/basic_event_serializer.rb
+++ b/plugins/discourse-events/app/serializers/discourse_events/events/basic_event_serializer.rb
@@ -67,47 +67,20 @@ module DiscourseEvents
end
def starts_at
- return object.starts_at&.utc&.strftime("%Y-%m-%d") if object.all_day
+ return object.starts_at.utc.strftime("%Y-%m-%d") if object.all_day
- if object.recurring? && object.recurrence_until.present? &&
- object.recurrence_until < Time.current
- return nil
- end
-
- timezone_time = object.starts_at&.in_time_zone(object.timezone)
-
- if object.show_local_time
- timezone_time&.strftime("%Y-%m-%dT%H:%M:%S")
- else
- timezone_time&.iso8601(3)
- end
+ format_time(object.starts_at)
end
def ends_at
return object.ends_at&.utc&.strftime("%Y-%m-%d") if object.all_day
- if object.recurring? && object.recurrence_until.present? &&
- object.recurrence_until < Time.current
- return nil
- end
-
- if object.show_local_time
- ends_at = object.ends_at || (object.starts_at && object.starts_at + 1.hour)
- timezone_ends_at = ends_at&.in_time_zone(object.timezone)
- timezone_ends_at&.strftime("%Y-%m-%dT%H:%M:%S")
- else
- if object.ends_at
- timezone_ends_at = object.ends_at&.in_time_zone(object.timezone)
- timezone_ends_at&.iso8601(3)
- else
- base_starts_at = object.starts_at&.in_time_zone(object.timezone)
- if base_starts_at
- (base_starts_at + 1.hour).iso8601(3)
- else
- nil
- end
- end
- end
+ format_time(object.ends_at || object.starts_at + 1.hour)
+ end
+
+ def format_time(time)
+ time = time.in_time_zone(object.timezone)
+ object.show_local_time ? time.strftime("%Y-%m-%dT%H:%M:%S") : time.iso8601(3)
end
def duration
diff --git a/plugins/discourse-events/assets/javascripts/discourse/components/discourse-post-event/dates.gjs b/plugins/discourse-events/assets/javascripts/discourse/components/discourse-post-event/dates.gjs
index 7d35357ef4a..20fef64db27 100644
--- a/plugins/discourse-events/assets/javascripts/discourse/components/discourse-post-event/dates.gjs
+++ b/plugins/discourse-events/assets/javascripts/discourse/components/discourse-post-event/dates.gjs
@@ -151,10 +151,6 @@ export default class DiscoursePostEventDates extends Component {
@action
async computeDates(element) {
- if (this.args.expiredAndRecurring) {
- return;
- }
-
if (this.args.event.allDay) {
const start = moment(this.args.event.startsAt, "YYYY-MM-DD");
const includeStartYear = !start.isSame(moment(), "year");
@@ -226,11 +222,7 @@ export default class DiscoursePostEventDates extends Component {
{{didInsert this.computeDates}}
>
{{dIcon "clock"}}
- {{#if @expiredAndRecurring}}
- -
- {{else}}
- {{this.htmlDates}}
- {{/if}}
+ {{this.htmlDates}}
</section>
</template>
}
diff --git a/plugins/discourse-events/assets/javascripts/discourse/components/discourse-post-event/index.gjs b/plugins/discourse-events/assets/javascripts/discourse/components/discourse-post-event/index.gjs
index 45df3b5d4e5..fd1d7e6f3cc 100644
--- a/plugins/discourse-events/assets/javascripts/discourse/components/discourse-post-event/index.gjs
+++ b/plugins/discourse-events/assets/javascripts/discourse/components/discourse-post-event/index.gjs
@@ -185,10 +185,6 @@ export default class DiscoursePostEvent extends Component {
return this.event.watchingInvitee?.status;
}
- get expiredAndRecurring() {
- return this.event.isExpired && this.event.recurrence;
- }
-
get recurrenceLabel() {
if (!this.event?.recurrence) {
return null;
@@ -228,7 +224,6 @@ export default class DiscoursePostEvent extends Component {
if (
fetched.recurrence &&
displayedStartsAt &&
- fetched.startsAt &&
displayedStartsAt !== fetched.startsAt
) {
this.#filterForFutureOccurrence(fetched);
@@ -278,20 +273,8 @@ export default class DiscoursePostEvent extends Component {
/>
<header class="event-header" {{this.setupMessageBus}}>
<div class="event-date">
- <div class="month">
- {{#if this.expiredAndRecurring}}
- -
- {{else}}
- {{this.startsAtMonth}}
- {{/if}}
- </div>
- <div class="day">
- {{#if this.expiredAndRecurring}}
- -
- {{else}}
- {{this.startsAtDay}}
- {{/if}}
- </div>
+ <div class="month">{{this.startsAtMonth}}</div>
+ <div class="day">{{this.startsAtDay}}</div>
</div>
<div class="event-info">
<span class="name">
@@ -360,9 +343,7 @@ export default class DiscoursePostEvent extends Component {
clamp=this.clampDescription
)
Location=(component DiscoursePostEventLocation event=event)
- Dates=(component
- Dates event=event expiredAndRecurring=this.expiredAndRecurring
- )
+ Dates=(component Dates event=event)
Recurrence=(component
InfoSection icon="arrows-rotate" class="event-recurrence"
)
@@ -380,10 +361,7 @@ export default class DiscoursePostEvent extends Component {
)
}}
>
- <Dates
- @event={{event}}
- @expiredAndRecurring={{this.expiredAndRecurring}}
- />
+ <Dates @event={{event}} />
{{#if event.recurrence}}
<InfoSection class="event-recurrence" @icon="arrows-rotate">
{{this.recurrenceLabel}}
diff --git a/plugins/discourse-events/lib/discourse_events/events/email_renderer.rb b/plugins/discourse-events/lib/discourse_events/events/email_renderer.rb
index f558ab6fae8..e78306beb2a 100644
--- a/plugins/discourse-events/lib/discourse_events/events/email_renderer.rb
+++ b/plugins/discourse-events/lib/discourse_events/events/email_renderer.rb
@@ -132,17 +132,21 @@ module DiscourseEvents
end
def dates
- return "-" if @event&.expired? && @event.recurring?
-
+ start_date, end_date = displayed_dates
suffix = timezone_suffix
- formatted = "#{format_date(starts_at)}#{suffix}"
-
- ends_at = event_node["data-end"]
- formatted = "#{formatted} → #{format_date(ends_at)}#{suffix}" if ends_at
+ formatted = "#{format_date(start_date)}#{suffix}"
+ formatted = "#{formatted} → #{format_date(end_date)}#{suffix}" if end_date
formatted
end
+ def displayed_dates
+ return starts_at, event_node["data-end"] if @event.nil?
+
+ serializer = BasicEventSerializer.new(@event, root: false)
+ [serializer.starts_at, serializer.ends_at]
+ end
+
def format_date(value)
format = all_day? ? "%B %-d, %Y" : "%B %-d, %Y %-I:%M %p"
DateTime.parse(value).strftime(format)
diff --git a/plugins/discourse-events/spec/jobs/regular/discourse_post_event/send_reminder_spec.rb b/plugins/discourse-events/spec/jobs/regular/discourse_post_event/send_reminder_spec.rb
index 14a3706da6d..4e2b62d2b24 100644
--- a/plugins/discourse-events/spec/jobs/regular/discourse_post_event/send_reminder_spec.rb
+++ b/plugins/discourse-events/spec/jobs/regular/discourse_post_event/send_reminder_spec.rb
@@ -621,8 +621,6 @@ describe Jobs::DiscoursePostEventSendReminder do
it "handles expired recurring events" do
DiscourseEvents::Events::Invitee.create_attendance!(going_user.id, expired_event.id, :going)
- expect(expired_event.starts_at).to be_nil
-
expect { send_reminder(expired_event) }.not_to change {
going_user.reload.unread_notifications
}
diff --git a/plugins/discourse-events/spec/lib/discourse_events/events/pretty_text_spec.rb b/plugins/discourse-events/spec/lib/discourse_events/events/pretty_text_spec.rb
index 656bab1adb4..7f7fd0adfa7 100644
--- a/plugins/discourse-events/spec/lib/discourse_events/events/pretty_text_spec.rb
+++ b/plugins/discourse-events/spec/lib/discourse_events/events/pretty_text_spec.rb
@@ -77,8 +77,7 @@ describe PrettyText do
cooked = PrettyText.cook(post_1.raw)
result = PrettyText.format_for_email(cooked, post_1)
- expect(result).to include("(America/New_York)")
- expect(result).to include("June 5, 2018 6:39 PM")
+ expect(result).to include("June 5, 2018 2:39 PM (America/New_York)")
end
end
@@ -339,12 +338,19 @@ describe PrettyText do
).reload
end
- it "does not display a stale date (matching the on-site card)" do
+ it "displays the last occurrence (matching the on-site card)" do
+ Fabricate(
+ :event_date,
+ event: post_1.event,
+ starts_at: Time.utc(2018, 5, 15, 10),
+ ends_at: Time.utc(2018, 5, 15, 11),
+ finished_at: Time.utc(2018, 5, 15, 11),
+ )
+
cooked = PrettyText.cook(post_1.raw)
result = PrettyText.format_for_email(cooked, post_1)
- expect(result).not_to include("May 1, 2018")
- expect(result).to include(">-</td>")
+ expect(result).to include("May 15, 2018 10:00 AM (UTC) → May 15, 2018 11:00 AM (UTC)")
end
end
diff --git a/plugins/discourse-events/spec/models/discourse_events/events/event_spec.rb b/plugins/discourse-events/spec/models/discourse_events/events/event_spec.rb
index 4fd96817a94..47ab0ed2510 100644
--- a/plugins/discourse-events/spec/models/discourse_events/events/event_spec.rb
+++ b/plugins/discourse-events/spec/models/discourse_events/events/event_spec.rb
@@ -1416,38 +1416,11 @@ RSpec.describe DiscourseEvents::Events::Event do
)
end
- it "returns nil for starts_at since no future dates can be computed" do
- expect(expired_recurring_event.starts_at).to be_nil
- end
-
- it "returns nil for ends_at since no future dates can be computed" do
- expect(expired_recurring_event.ends_at).to be_nil
- end
-
- it "serializer handles nil starts_at correctly" do
- serializer =
- DiscourseEvents::Events::EventSerializer.new(
- expired_recurring_event,
- scope: Guardian.new,
- root: false,
- )
- json = JSON.parse(serializer.to_json)
-
- expect(json["starts_at"]).to be_nil
- expect(json["ends_at"]).to be_nil
- end
-
- it "basic serializer handles expired recurring events correctly" do
- serializer =
- DiscourseEvents::Events::BasicEventSerializer.new(
- expired_recurring_event,
- root: false,
- scope: Guardian.new,
- )
- json = JSON.parse(serializer.to_json)
-
- expect(json["starts_at"]).to be_nil
- expect(json["ends_at"]).to be_nil
+ it "keeps the last known dates" do
+ expect(expired_recurring_event.starts_at).to eq_time(
+ expired_recurring_event.original_starts_at,
+ )
+ expect(expired_recurring_event.ends_at).to eq_time(expired_recurring_event.original_ends_at)
end
end
diff --git a/plugins/discourse-events/spec/system/post_event_spec.rb b/plugins/discourse-events/spec/system/post_event_spec.rb
index c7111be39d7..03100fdba4e 100644
--- a/plugins/discourse-events/spec/system/post_event_spec.rb
+++ b/plugins/discourse-events/spec/system/post_event_spec.rb
@@ -378,20 +378,27 @@ describe "Post event" do
end
end
- it "shows '-' for expired recurring events instead of dates" do
- title = "An expired recurring event"
+ it "keeps showing the last occurrence of an expired recurring event" do
+ freeze_time Time.utc(2026, 8, 31)
raw = <<~MD
- [event start='2024-01-01 10:00' recurrenceUntil='2025-07-31' recurrence='every_week']
+ [event start='2026-09-01 10:00' end='2026-09-01 11:00' recurrence='every_week' recurrenceUntil='2026-09-22 23:59']
[/event]
MD
- post = PostCreator.create!(admin, title:, raw:)
+ post = PostCreator.create!(admin, title: "An expired recurring event", raw:)
+ PostCreator.create!(admin, topic_id: post.topic_id, raw: "Minutes of the last meeting")
+ [1, 8, 15, 22].each do |day|
+ freeze_time Time.utc(2026, 9, day, 11, 1)
+ Jobs::DiscourseCalendar::MonitorEventDates.new.execute({})
+ end
+
+ freeze_time Time.utc(2026, 9, 24)
visit(post.topic.url)
- expect(page).to have_css(".discourse-post-event")
- expect(page).to have_css(".event-date .month", text: "-")
- expect(page).to have_css(".event-date .day", text: "-")
- expect(page).to have_css(".event-dates", text: "-")
+ expect(page).to have_css(".event-date .month", text: "SEP")
+ expect(page).to have_css(".event-date .day", text: "22")
+ expect(page).to have_css(".event-dates .discourse-local-date")
+ expect(page).to have_css("#post_2", text: "Minutes of the last meeting")
end
context "with DST handling for recurring events" do