feat: auto generate placeholder nationalId for users and professors, auto calculate class end date
This commit is contained in:
+27
-1
@@ -109,6 +109,31 @@ const buildClassScheduleContext = (classDoc, sessions = [], currentSession = nul
|
||||
};
|
||||
};
|
||||
|
||||
const calculateClassEndDate = (startDate, days = [], numberOfSessions = 0) => {
|
||||
const date = toDate(startDate);
|
||||
const countNeeded = parseInt(numberOfSessions, 10);
|
||||
if (!date || isNaN(countNeeded) || countNeeded < 1) return null;
|
||||
const validDays = normalizeWeekdays(days);
|
||||
if (!validDays.length) return null;
|
||||
|
||||
let current = new Date(date);
|
||||
let count = 0;
|
||||
let lastMatchingDate = null;
|
||||
let safetyLimit = 365 * 5;
|
||||
|
||||
while (count < countNeeded && safetyLimit > 0) {
|
||||
safetyLimit--;
|
||||
if (validDays.includes(current.getDay())) {
|
||||
count++;
|
||||
lastMatchingDate = new Date(current);
|
||||
}
|
||||
if (count >= countNeeded) break;
|
||||
current.setDate(current.getDate() + 1);
|
||||
}
|
||||
|
||||
return lastMatchingDate;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
IRAN_WEEK_ORDER,
|
||||
PERSIAN_WEEKDAYS,
|
||||
@@ -118,5 +143,6 @@ module.exports = {
|
||||
formatClassStartDate,
|
||||
normalizeWeekdays,
|
||||
normalizeClockTime,
|
||||
buildClassScheduleContext
|
||||
buildClassScheduleContext,
|
||||
calculateClassEndDate
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user