(expiresAt: string, now = Date.now())
| 42 | |
| 43 | /** "until Sun", or "until Thu, Oct 22" when the weekday alone is ambiguous. */ |
| 44 | export const formatUntil = (expiresAt: string, now = Date.now()): string => { |
| 45 | const until = new Date(expiresAt); |
| 46 | const weekday = until.toLocaleDateString('en-US', { weekday: 'short' }); |
| 47 | return until.getTime() - now < 6 * dayMs |
| 48 | ? `until ${weekday}` |
| 49 | : `until ${weekday}, ${until.toLocaleDateString('en-US', { |
| 50 | month: 'short', |
| 51 | day: 'numeric', |
| 52 | })}`; |
| 53 | }; |
no test coverage detected