next_weekday(d, target) returning the next date strictly after d whose weekday() equals target (0=Monday … 6=Sunday). If d itself is a Monday and target is 0, the answer is the following Monday, seven days on. Solve with modular arithmetic, not a loop.next_weekday(date(2026, 7, 28), 0) # a Tuesday
date(2026, 8, 3)
The Monday after Tuesday July 28 is August 3.
days_ahead = (target - d.weekday() + 7) % 7 — but map 0 to 7.
Or: (target - d.weekday() - 1) % 7 + 1.