The weeb for the next gen discord boat - Wamellow wamellow.com
bot discord
at master 715 B view raw
1export function formatDate(dateString: string, userLanguage: string): string { 2 const date = new Date(dateString); 3 const today = new Date(); 4 const yesterday = new Date(today); 5 yesterday.setDate(today.getDate() - 1); 6 7 const options: Intl.DateTimeFormatOptions = { 8 hour: "numeric", 9 minute: "numeric" 10 }; 11 12 const dateFormatter = new Intl.DateTimeFormat(userLanguage, options); 13 14 if (date.toDateString() === today.toDateString()) { 15 return `Today at ${dateFormatter.format(date)}`; 16 } else if (date.toDateString() === yesterday.toDateString()) { 17 return `Yesterday at ${dateFormatter.format(date)}`; 18 } 19 return date.toLocaleDateString(userLanguage); 20 21}