changes whatapp message date format

This commit is contained in:
Abhijit 2026-11-13 11:04:37 +05:30
parent 9cddf60047
commit d838fa8a18
3 changed files with 16 additions and 4 deletions

View File

@ -20,6 +20,7 @@ import {
weekdayOf, weekdayOf,
} from './schedule.js'; } from './schedule.js';
import { getAppSettings } from './settings.js'; import { getAppSettings } from './settings.js';
import { toDmy } from './whatsappFormat.js';
import { toCohortSessionDto } from '../utils/serialize.js'; import { toCohortSessionDto } from '../utils/serialize.js';
const LIVE_STATUSES = ['confirmed', 'active']; const LIVE_STATUSES = ['confirmed', 'active'];
@ -441,7 +442,8 @@ export async function pushSession(session, reason, { notifyAdmins = false } = {}
const { notifyGroupSessionChange } = await import('./whatsapp.js'); const { notifyGroupSessionChange } = await import('./whatsapp.js');
await notifyGroupSessionChange( await notifyGroupSessionChange(
cohort._id, cohort._id,
`The ${fromDate} session for ${cohort.name} was ${reason || 'cancelled'}. The next session will be on the next meeting day.`, // `The ${fromDate} session for ${cohort.name} was ${reason || 'cancelled'}. The next session will be on the next meeting day.`,
`The ${toDmy(fromDate)} session for ${cohort.name} was ${reason || 'cancelled'}. The next session will be on the next meeting day.`,
); );
return { cancelled: session, appended: null }; return { cancelled: session, appended: null };
} }
@ -508,7 +510,8 @@ export async function shiftApprovedLeaveSessions(prtId, startYmd, endYmd) {
const { notifyGroupSessionChange } = await import('./whatsapp.js'); const { notifyGroupSessionChange } = await import('./whatsapp.js');
await notifyGroupSessionChange( await notifyGroupSessionChange(
cohort._id, cohort._id,
`The ${fromDate} session for ${cohort.name} was Approved PRT leave. The replacement date is ${toDate}.`, // `The ${fromDate} session for ${cohort.name} was Approved PRT leave. The replacement date is ${toDate}.`,
`The ${toDmy(fromDate)} session for ${cohort.name} was Approved PRT leave. The replacement date is ${toDmy(toDate)}.`,
); );
shifted.push({ cohortId: String(cohort._id), fromDate, toDate }); shifted.push({ cohortId: String(cohort._id), fromDate, toDate });
} }

View File

@ -17,6 +17,7 @@ import {
reminderFireAt, reminderFireAt,
renderTemplate, renderTemplate,
templateBody, templateBody,
toDmy,
} from './whatsappFormat.js'; } from './whatsappFormat.js';
const LIVE = new Set(['active', 'confirmed']); const LIVE = new Set(['active', 'confirmed']);
@ -116,7 +117,8 @@ function sessionVars(session, cohort) {
const { startTime } = slotDateTimes(session.date, session.slot || cohort.slot, cohort.durationMinutes || 60); const { startTime } = slotDateTimes(session.date, session.slot || cohort.slot, cohort.durationMinutes || 60);
return { return {
cohort: cohort.name || '', cohort: cohort.name || '',
date: session.date || '', // date: session.date || '',
date: toDmy(session.date),
time: session.slot || startTime || '', time: session.slot || startTime || '',
meetUrl: session.meetUrl || '', meetUrl: session.meetUrl || '',
prtName: personName(prt), prtName: personName(prt),

View File

@ -35,9 +35,16 @@ export function groupSubject(cohort) {
return subject.length <= SUBJECT_LIMIT ? subject : subject.slice(0, SUBJECT_LIMIT).trim(); return subject.length <= SUBJECT_LIMIT ? subject : subject.slice(0, SUBJECT_LIMIT).trim();
} }
// "2026-11-13" to "13-11-2026" for WhatsApp messages.
export function toDmy(ymd) {
const [y, m, d] = String(ymd || '').split('-');
return y && m && d ? `${d}-${m}-${y}` : String(ymd || '');
}
export function groupDescription(cohort, startYmd = '') { export function groupDescription(cohort, startYmd = '') {
const titled = `${SUBJECT_PREFIX}${String(cohort?.name || '').trim() || 'Cohort'}`; const titled = `${SUBJECT_PREFIX}${String(cohort?.name || '').trim() || 'Cohort'}`;
const parts = [titled, cohort?.slot, cohort?.language, startYmd ? `starts ${startYmd}` : ''] // const parts = [titled, cohort?.slot, cohort?.language, startYmd ? `starts ${startYmd}` : '']
const parts = [titled, cohort?.slot, cohort?.language, startYmd ? `starts ${toDmy(startYmd)}` : '']
.map((part) => String(part || '').trim()) .map((part) => String(part || '').trim())
.filter(Boolean); .filter(Boolean);
return parts.join(' · '); return parts.join(' · ');