( value: Date | number | string, now = new Date(), )
| 32 | }; |
| 33 | |
| 34 | export const publishTimeRelativeShort = ( |
| 35 | value: Date | number | string, |
| 36 | now = new Date(), |
| 37 | ): string => { |
| 38 | const date = new Date(value); |
| 39 | |
| 40 | // Calculate time delta in seconds. |
| 41 | const dt = (now.getTime() - date.getTime()) / 1000; |
| 42 | |
| 43 | if (dt <= oneMinute) { |
| 44 | return 'now'; |
| 45 | } |
| 46 | |
| 47 | if (dt <= oneHour) { |
| 48 | const numMinutes = Math.round(dt / oneMinute); |
| 49 | return `${numMinutes}m`; |
| 50 | } |
| 51 | |
| 52 | if (dt <= oneDay) { |
| 53 | const numHours = Math.round(dt / oneHour); |
| 54 | return `${numHours}h`; |
| 55 | } |
| 56 | |
| 57 | if (dt <= oneWeek) { |
| 58 | const numDays = Math.round(dt / oneDay); |
| 59 | return `${numDays}d`; |
| 60 | } |
| 61 | |
| 62 | if (dt <= oneYear) { |
| 63 | const numWeeks = Math.round(dt / oneWeek); |
| 64 | return `${numWeeks}w`; |
| 65 | } |
| 66 | |
| 67 | const numYears = Math.round(dt / oneYear); |
| 68 | return `${numYears}y`; |
| 69 | }; |
| 70 | |
| 71 | // Full, readable date for the notification timestamp tooltip — e.g. |
| 72 | // "15 April 2024 at 14:30". |
no outgoing calls
no test coverage detected