Recurring date is showing wrong next date

AI-generated summary

A bug has been reported in the Recurring date feature, where the next occurrence is shown incorrectly when the initial date is in the future. seanblue provided an example where the recurring date shows February 28, 2021 instead of January 24, 2021. eviltrout investigated the issue and found that the code bases the recurring date on the difference between the current date and today, which seems intentional but incorrect for future dates.

Joffreyjaffeux acknowledged the bug and will look into it. A fix has been proposed in this GitHub pull request and is awaiting review.

I’m trying to set up a recurring date as follows:

[date=2021-01-24 time=08:30:00 timezone="America/New_York" recurring="1.weeks"]

Since this date is in the future, it should show January 24, 2021 as the next occurrence. Instead, it’s showing February 28, 2021.

Actual date:
2021-01-24T13:30:00Z

Screenshot from post preview (in case the preview shows it differently):
image


Changing the date to 2021-01-25 jumps the date all the way to March 8, 2021, skipping 8 days instead of 1 day. Every 7th day it jumps an extra week, which seems to be why the date is so off. Am I doing something wrong here? Maybe there’s an edge case with creating recurring dates that are in the future in general or in a future year specifically.

2 Likes

This seems oddly intentional from the code. It always seems to base the recurring date off the different between the current date and today:

https://github.com/discourse/discourse/blob/master/plugins/discourse-local-dates/assets/javascripts/lib/local-date-builder.js.es6#L55

I tried changing this in the code to be localDate.datetime and the output was correct in the browser but 4 tests failed. It seemed they were ensuring it works this way, so now I’m wondering if I’m missing something @j.jaffeux? Recurring should be after the date you entered not the current date right?

4 Likes

Yes indeed I think I have overlooked this case and mostly took into consideration when you try to create a date in past and recurring will make it happen in future. Will have a look next week.

7 Likes

This is awaiting review, but that should fix it once merged:

https://github.com/discourse/discourse/pull/11587

Thanks for the report, I’m happy to have this bug out of the way.

7 Likes