amountFormatter.ts
9 months ago
formatTimestamp.ts
9 months ago
getRelativeTimeString.ts
9 months ago
prepareDefaultValuesFromSchema.ts
9 months ago
getRelativeTimeString.ts
15 lines
| 1 | import {formatDistanceToNow} from 'date-fns'; |
| 2 | |
| 3 | /** |
| 4 | * Returns a relative time string for a given date (e.g. "Today" or "2 days ago") |
| 5 | * |
| 6 | * @since 4.10.0 |
| 7 | */ |
| 8 | export function getRelativeTimeString(date: Date): string { |
| 9 | const now = new Date(); |
| 10 | if (date.toDateString() === now.toDateString()) { |
| 11 | return 'Today'; |
| 12 | } |
| 13 | return formatDistanceToNow(date, {addSuffix: true}); |
| 14 | } |
| 15 |