const HttpError = require('./httpError'); function normalizeDate(dateValue, fieldName = 'date') { const rawValue = String(dateValue || '').trim(); if (/^\d{4}-\d{2}-\d{2}$/.test(rawValue)) { return rawValue; } if (/^\d{2}\/\d{2}\/\d{4}$/.test(rawValue)) { const [day, month, year] = rawValue.split('/'); return `${year}-${month}-${day}`; } throw new HttpError( 400, `${fieldName} must use YYYY-MM-DD or DD/MM/YYYY format.`, 'INVALID_DATE', ); } function mysqlDateTimeFromNow(daysAhead) { const expiryDate = new Date(Date.now() + daysAhead * 24 * 60 * 60 * 1000); return expiryDate.toISOString().slice(0, 19).replace('T', ' '); } module.exports = { normalizeDate, mysqlDateTimeFromNow, };