mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import {I18n} from '@lingui/core' 2 3export function niceDate(i18n: I18n, date: number | string | Date) { 4 const d = new Date(date) 5 6 return i18n.date(d, { 7 dateStyle: 'long', 8 timeStyle: 'short', 9 }) 10} 11 12export function getAge(birthDate: Date): number { 13 var today = new Date() 14 var age = today.getFullYear() - birthDate.getFullYear() 15 var m = today.getMonth() - birthDate.getMonth() 16 if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) { 17 age-- 18 } 19 return age 20} 21 22/** 23 * Compares two dates by year, month, and day only 24 */ 25export function simpleAreDatesEqual(a: Date, b: Date): boolean { 26 return ( 27 a.getFullYear() === b.getFullYear() && 28 a.getMonth() === b.getMonth() && 29 a.getDate() === b.getDate() 30 ) 31}