export function toDDMMYYYY(dateString?: string | null): string | null { if (!dateString) return null; // Ensure dateString is valid format YYYY-MM-DD const regex = /^\d{4}-\d{2}-\d{2}$/; if (!regex.test(dateString)) { throw new Error( `Invalid date format: ${dateString}. Expected format is YYYY-MM-DD`, ); } const [year, month, day] = dateString.split('-'); return `${day}-${month}-${year}`; } export function toMMYYYY(dateString?: string | null): string | null { if (!dateString) return null; // Ensure dateString is valid format YYYY-MM const regex = /^\d{4}-\d{2}$/; if (!regex.test(dateString)) { throw new Error( `Invalid date format: ${dateString}. Expected format is YYYY-MM`, ); } const [year, month] = dateString.split('-'); return `${month}-${year}`; } export function filterByMonth(data: any[], monthDate: string) { const [year, month] = monthDate.split('-').map(Number); return data.filter((item) => { const itemDate = new Date(item.date); return ( itemDate.getUTCFullYear() === year && itemDate.getUTCMonth() + 1 === month ); }); }