Fixing a bug with displaying the next recurrence of a weekly event with the help of automated testing.

On the morning of Sunday, November 9th, 2025, I deployed an update to dmvboardgames.com to show information about groups a user joined and dates of recurring events that a user had an RSVP to attend.

I navigated to my user page shortly afterwards in the morning and saw that it was showing Sunday, November 16th as the next event date for the two events I host on Sundays. Since the current date was November 9th, the next event dates should’ve been displayed on November 9th.

I narrowed down the root cause to the following line of code on the backend. It made the next event date 7 days in the future if the user member page was accessed on the day of an event, regardless of whether the current time was before or after the event start time.

LocalDate nextEventDate = LocalDate.now().with(TemporalAdjusters.next(DayOfWeek.valueOf(eventDay.toUpperCase())));

The test also had the start date in the future. I added a pause if the test was being run at midnight and rewrote the test case with the following code.

LocalDate expectedDate = LocalDate.now();
LocalDate startDate = eventFromDb.getStartDate();
assertEquals(expectedDate, startDate);

Then I rewrote the next event date calculation.

LocalDate nextEventDate = LocalDate.now();
DayOfWeek eventDayValue = DayOfWeek.valueOf(eventDay.toUpperCase());
if(!eventDayValue.equals(nextEventDate.getDayOfWeek())){
nextEventDate = nextEventDate.with(TemporalAdjusters.next(eventDayValue));
}

Afterwards, the test passed.

I then added another test case for an event that was on a day that wasn’t the current one.

After fixing another test case that was incorrectly using the next day as a next event occurrence, all the tests passed.

I merged the changes to the main branch, then deployed to the release branch, and created a new release.

After the release build was complete, I started a production deployment.

After the deployment, my user page correctly showed the next occurrence of the two events I host on November 9th.