( value: Date | number | string, now = new Date(), )
| 106 | } |
| 107 | |
| 108 | export function postDateFormat( |
| 109 | value: Date | number | string, |
| 110 | now = new Date(), |
| 111 | ): string { |
| 112 | const date = new Date(value); |
| 113 | |
| 114 | // Calculate time delta in seconds. |
| 115 | const dt = (now.getTime() - date.getTime()) / 1000; |
| 116 | |
| 117 | if (dt <= oneMinute) { |
| 118 | return 'Now'; |
| 119 | } |
| 120 | |
| 121 | if (isSameDay(date, now)) { |
| 122 | return 'Today'; |
| 123 | } |
| 124 | |
| 125 | if (isSameDay(date, subDays(now, 1))) { |
| 126 | return 'Yesterday'; |
| 127 | } |
| 128 | |
| 129 | const options: Intl.DateTimeFormatOptions = { |
| 130 | month: 'short', |
| 131 | day: '2-digit', |
| 132 | }; |
| 133 | if (!isSameYear(date, now)) { |
| 134 | options.year = 'numeric'; |
| 135 | } |
| 136 | return date.toLocaleString('en-US', options); |
| 137 | } |
| 138 | |
| 139 | export function postUpdatedDateFormat( |
| 140 | value: Date | number | string, |
no outgoing calls
no test coverage detected