feat(classes): store weekdays and meeting times on the class

Keep the class schedule on the class itself so SMS and listings do not have to infer days and hours from sessions.
This commit is contained in:
2026-08-15 23:59:07 +03:30
parent 192c595c68
commit 4d60755a95
5 changed files with 112 additions and 9 deletions
+39
View File
@@ -6,6 +6,9 @@ const {
formatCourseTime,
formatClassDays,
formatClassStartDate,
formatClassDaysFromIndexes,
normalizeWeekdays,
normalizeClockTime,
buildClassScheduleContext
} = require('./classSchedule');
@@ -56,4 +59,40 @@ describe('class schedule SMS helpers', () => {
assert.equal(context.courseTime, 'از 10 تا 12');
});
it('prefers stored class days and times over inferred sessions', () => {
const atNoon = (year, month, day) => new Date(year, month - 1, day, 12, 0, 0);
const context = buildClassScheduleContext(
{
startDate: atNoon(2026, 8, 15),
days: [6, 1],
startTime: '18:00',
endTime: '20:00'
},
[
{ day: atNoon(2026, 8, 16), startTime: '19:00', endTime: '21:00' }
]
);
assert.equal(context.classDays, 'شنبه و دوشنبه');
assert.equal(context.courseTime, 'از 18 تا 20');
});
});
describe('class weekday and time normalization', () => {
it('deduplicates weekdays and sorts them in Iran week order', () => {
assert.deepEqual(normalizeWeekdays([1, 6, 1, 3, 9, '2']), [6, 1, 2, 3]);
});
it('normalizes clock times to HH:mm', () => {
assert.equal(normalizeClockTime('19'), '19:00');
assert.equal(normalizeClockTime('9:5'), '09:05');
assert.equal(normalizeClockTime('19:00'), '19:00');
assert.equal(normalizeClockTime('25:00'), '');
assert.equal(normalizeClockTime(''), '');
});
it('formats stored weekday indexes as Persian day names', () => {
assert.equal(formatClassDaysFromIndexes([1, 6]), 'شنبه و دوشنبه');
});
});