( value: Date | number | string, now = new Date(), )
| 91 | } |
| 92 | |
| 93 | export function postDateFormat( |
| 94 | value: Date | number | string, |
| 95 | now = new Date(), |
| 96 | ): string { |
| 97 | const date = new Date(value); |
| 98 | |
| 99 | // Calculate time delta in seconds. |
| 100 | const dt = (now.getTime() - date.getTime()) / 1000; |
| 101 | |
| 102 | if (dt <= oneMinute) { |
| 103 | return 'Now'; |
| 104 | } |
| 105 | |
| 106 | if (isSameDay(date, now)) { |
| 107 | return 'Today'; |
| 108 | } |
| 109 | |
| 110 | if (isSameDay(date, subDays(now, 1))) { |
| 111 | return 'Yesterday'; |
| 112 | } |
| 113 | |
| 114 | const options: Intl.DateTimeFormatOptions = { |
| 115 | month: 'short', |
| 116 | day: '2-digit', |
| 117 | }; |
| 118 | if (!isSameYear(date, now)) { |
| 119 | options.year = 'numeric'; |
| 120 | } |
| 121 | return date.toLocaleString('en-US', options); |
| 122 | } |
| 123 | |
| 124 | export function postUpdatedDateFormat( |
| 125 | value: Date | number | string, |
no outgoing calls
no test coverage detected