| 154 | * @__NO_SIDE_EFFECTS__ |
| 155 | */ |
| 156 | export function useTimeAgo<UnitNames extends string = UseTimeAgoUnitNamesDefault>(time: MaybeRefOrGetter<Date | number | string>, options: UseTimeAgoOptions<boolean, UnitNames> = {}) { |
| 157 | const { |
| 158 | controls: exposeControls = false, |
| 159 | scheduler = getDefaultScheduler(options), |
| 160 | } = options |
| 161 | |
| 162 | const { now, ...controls } = useNow({ |
| 163 | scheduler, |
| 164 | controls: true, |
| 165 | }) |
| 166 | |
| 167 | const timeAgo = computed(() => formatTimeAgo(new Date(toValue(time)), options, toValue(now))) |
| 168 | |
| 169 | if (exposeControls) { |
| 170 | return { |
| 171 | timeAgo, |
| 172 | ...controls, |
| 173 | } |
| 174 | } |
| 175 | else { |
| 176 | return timeAgo |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | export function formatTimeAgo<UnitNames extends string = UseTimeAgoUnitNamesDefault>(from: Date, options: FormatTimeAgoOptions<UnitNames> = {}, now: Date | number = Date.now()): string { |
| 181 | const { |