From d838fa8a1810af175fb89a39024780c271abf25b Mon Sep 17 00:00:00 2001 From: Abhijit Date: Fri, 13 Nov 2026 11:04:37 +0530 Subject: [PATCH] changes whatapp message date format --- backend/src/services/programSessions.js | 7 +++++-- backend/src/services/whatsapp.js | 4 +++- backend/src/services/whatsappFormat.js | 9 ++++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/backend/src/services/programSessions.js b/backend/src/services/programSessions.js index 016bb12..fd17935 100644 --- a/backend/src/services/programSessions.js +++ b/backend/src/services/programSessions.js @@ -20,6 +20,7 @@ import { weekdayOf, } from './schedule.js'; import { getAppSettings } from './settings.js'; +import { toDmy } from './whatsappFormat.js'; import { toCohortSessionDto } from '../utils/serialize.js'; const LIVE_STATUSES = ['confirmed', 'active']; @@ -441,7 +442,8 @@ export async function pushSession(session, reason, { notifyAdmins = false } = {} const { notifyGroupSessionChange } = await import('./whatsapp.js'); await notifyGroupSessionChange( 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 }; } @@ -508,7 +510,8 @@ export async function shiftApprovedLeaveSessions(prtId, startYmd, endYmd) { const { notifyGroupSessionChange } = await import('./whatsapp.js'); await notifyGroupSessionChange( 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 }); } diff --git a/backend/src/services/whatsapp.js b/backend/src/services/whatsapp.js index a29d38f..b3acc8a 100644 --- a/backend/src/services/whatsapp.js +++ b/backend/src/services/whatsapp.js @@ -17,6 +17,7 @@ import { reminderFireAt, renderTemplate, templateBody, + toDmy, } from './whatsappFormat.js'; 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); return { cohort: cohort.name || '', - date: session.date || '', + // date: session.date || '', + date: toDmy(session.date), time: session.slot || startTime || '', meetUrl: session.meetUrl || '', prtName: personName(prt), diff --git a/backend/src/services/whatsappFormat.js b/backend/src/services/whatsappFormat.js index 7733529..9b1e290 100644 --- a/backend/src/services/whatsappFormat.js +++ b/backend/src/services/whatsappFormat.js @@ -35,9 +35,16 @@ export function groupSubject(cohort) { 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 = '') { 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()) .filter(Boolean); return parts.join(' ยท ');