Something went wrong. Try again.
Bluesky app fork with some witchin' additions 馃挮 forked from jollywhoppers.com/witchsky.app
Something went wrong. Try again.
1.6 kB 路 64 lines
TypeScript
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465import {type I18n} from '@lingui/core'import {msg} from '@lingui/macro'
export function niceDate( i18n: I18n, date: number | string | Date, dateStyle: 'short' | 'medium' | 'long' | 'full' | 'dot separated' = 'long',) { const d = new Date(date)
if (dateStyle === 'dot separated') { return i18n._( msg({ context: 'date and time formatted like this: [time] 路 [date]', message: `${i18n.date(d, {timeStyle: 'short'})} 路 ${i18n.date(d, {dateStyle: 'medium'})}`, }), ) }
return i18n.date(d, { dateStyle, timeStyle: 'short', })}
export function getAge(birthDate: Date): number { var today = new Date() var age = today.getFullYear() - birthDate.getFullYear() var m = today.getMonth() - birthDate.getMonth() if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) { age-- } return age}
/** * Get a Date object that is N years ago from now * @param years number of years * @returns Date object */export function getDateAgo(years: number): Date { const date = new Date() date.setFullYear(date.getFullYear() - years) return date}
/** * Compares two dates by year, month, and day only */export function simpleAreDatesEqual(a: Date, b: Date): boolean { return ( a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate() )}
export function formatJoinDate(date: number | string | Date): string { const d = new Date(date) return d.toLocaleDateString('en-US', { month: 'short', year: 'numeric', })}