(date: DateTimeInput)
| 105 | * sidebar timestamps. |
| 106 | */ |
| 107 | export function shortRelativeTime(date: DateTimeInput): string { |
| 108 | const now = dayjs(); |
| 109 | const then = dayjs(date); |
| 110 | const diffSeconds = now.diff(then, "second"); |
| 111 | |
| 112 | if (diffSeconds < 60) { |
| 113 | return "now"; |
| 114 | } |
| 115 | const diffMinutes = now.diff(then, "minute"); |
| 116 | if (diffMinutes < 60) { |
| 117 | return `${diffMinutes}m`; |
| 118 | } |
| 119 | const diffHours = now.diff(then, "hour"); |
| 120 | if (diffHours < 24) { |
| 121 | return `${diffHours}h`; |
| 122 | } |
| 123 | const diffDays = now.diff(then, "day"); |
| 124 | if (diffDays < 7) { |
| 125 | return `${diffDays}d`; |
| 126 | } |
| 127 | const diffWeeks = now.diff(then, "week"); |
| 128 | if (diffWeeks < 5) { |
| 129 | return `${diffWeeks}w`; |
| 130 | } |
| 131 | const diffMonths = now.diff(then, "month"); |
| 132 | if (diffMonths < 12) { |
| 133 | return `${diffMonths}mo`; |
| 134 | } |
| 135 | const diffYears = now.diff(then, "year"); |
| 136 | return `${diffYears}y`; |
| 137 | } |
| 138 | |
| 139 | export function relativeTimeWithoutSuffix(date: DateTimeInput) { |
| 140 | return dayjs(date).fromNow(true); |
no test coverage detected