discourse/plugins/automation/spec
Kris de8f59edf5
FIX: Automation Plugin - Monthly recurring triggers shifting dates and skipping months (BYDAY to BYMONTHDAY) (#40747)
Cleaning up what @Lillinator was working on over here:
https://github.com/discourse/discourse/pull/39917

Description:

Context / Bug:
Currently, when an admin sets a monthly recurring automation, the script
attempts to calculate the "Nth Weekday" (e.g., "The 3rd Tuesday") using
BYDAY instead of the actual calendar date. This causes two major issues
for administrators:

1. Shifting Dates: Users expect a monthly report to run on the exact
same calendar date (e.g., the 15th). Instead, the date shifts back and
forth depending on when the "3rd Tuesday" or "2nd Friday" falls in the
following month.
2. Silent Failures: If an admin sets a start date on the 30th or 31st of
a month (e.g., the 5th Tuesday), the automation generates a rule like
BYDAY=5TU. Months that only have 4 Tuesdays will completely fail to find
a valid execution date and silently skip the entire month.

Changes:

* Replaced the BYDAY string calculation with
BYMONTHDAY=#{start_date.day}. Monthly schedules will now reliably
trigger on the exact calendar date matching user expectations.
* Removed the now-unused count while-loop that was calculating the
weekday occurrence.
* Minor cleanup: Swapped Time.now for Time.zone.now in the RRule bounds
check for standard Rails timezone consistency.

Test Updates:

* Updated two existing assertions in recurring_spec.rb. The original
tests were explicitly (and incorrectly) expecting the buggy Nth-weekday
drift. I corrected the assertion dates to expect the proper exact
calendar day.

Files Touched:

*
plugins/discourse-automation/lib/discourse_automation/triggers/recurring.rb
*
plugins/discourse-automation/spec/lib/discourse_automation/triggers/recurring_spec.rb
2026-06-16 11:46:43 -04:00
..
fabricators FIX: ensures global notices are destroyed on post created (#28684) 2024-09-02 21:17:10 +02:00
integration DEV: Make automation recursion depth configurable (#40778) 2026-06-11 09:41:00 +10:00
jobs FIX: Destroy pending PM after an unexpected send error (#40461) 2026-06-02 10:02:51 -03:00
lib FEATURE: Allow nested automation triggers up to a recursion limit (#40672) 2026-06-09 17:03:36 +02:00
models DEV: Make automation recursion depth configurable (#40778) 2026-06-11 09:41:00 +10:00
requests FEATURE: Track automation errors and improve logging (#36938) 2026-01-19 18:50:13 +01:00
scripts FIX: Prevent automation set_topic_timer from reopening closed topics (#39375) 2026-04-21 15:08:31 +02:00
serializers DEV: Clean up state to prevent flaky tests (#27397) 2024-06-10 08:41:03 +08:00
services DEV: Refactor automation Update service per PR #36458 feedback (#36771) 2025-12-18 18:16:03 +01:00
system DEV: Enable Rails/FilePath rubocop rule (#40097) 2026-05-19 19:07:54 +02:00
triggers FIX: Automation Plugin - Monthly recurring triggers shifting dates and skipping months (BYDAY to BYMONTHDAY) (#40747) 2026-06-16 11:46:43 -04:00
plugin_helper.rb