const cron = require("node-cron"); const moment = require("moment") const scheduleAppointmentNotification = (formattedDate) => { const notificationTimes = [ { time: moment(formattedDate).subtract(20, "minutes"), message: "Randevunuz 30 dakika sonra başlıyor!" }, { time: moment(formattedDate).subtract(15, "minutes"), message: "Randevunuz 15 dakika sonra başlıyor!" }, ]; console.log("notificationTimes", notificationTimes) notificationTimes.forEach(({ time, message }) => { const cronExpression = `${time.minutes()} ${time.hours()} ${time.date()} ${time.month() + 1} *`; console.log(cronExpression) if (time.isAfter(moment())) { cron.schedule(cronExpression, () => { console.log("mesaj", message); }); } else{ console.log("dışında") } }); }; scheduleAppointmentNotification(new Date("2024-11-28T20:02:55.939Z").toISOString()) console.log("Started")