mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1export function niceDate(date: number | string | Date) {
2 const d = new Date(date)
3 return `${d.toLocaleDateString('en-us', {
4 year: 'numeric',
5 month: 'short',
6 day: 'numeric',
7 })} at ${d.toLocaleTimeString(undefined, {
8 hour: 'numeric',
9 minute: '2-digit',
10 })}`
11}
12
13export function getAge(birthDate: Date): number {
14 var today = new Date()
15 var age = today.getFullYear() - birthDate.getFullYear()
16 var m = today.getMonth() - birthDate.getMonth()
17 if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
18 age--
19 }
20 return age
21}
22
23/**
24 * Compares two dates by year, month, and day only
25 */
26export function simpleAreDatesEqual(a: Date, b: Date): boolean {
27 return (
28 a.getFullYear() === b.getFullYear() &&
29 a.getMonth() === b.getMonth() &&
30 a.getDate() === b.getDate()
31 )
32}