const q = "891811 de lundi"; const days = ['dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi']; const today = new Date(); let fallbackDate = null; const foundDay = days.find(d => q.includes(d)); if (foundDay) { const currentDay = today.getDay(); const targetDay = days.indexOf(foundDay); let diff = targetDay - currentDay; if (diff < 0) diff += 7; // next occurrence of that day if (diff === 0 && q.includes('prochain')) diff += 7; const targetDate = new Date(today); targetDate.setDate(today.getDate() + diff); fallbackDate = targetDate.toISOString().split('T')[0]; } console.log(fallbackDate);