MCPcopy
hub / github.com/vueuse/vueuse / useTimeAgo

Function useTimeAgo

packages/core/useTimeAgo/index.ts:156–178  ·  view source on GitHub ↗
(time: MaybeRefOrGetter<Date | number | string>, options: UseTimeAgoOptions<boolean, UnitNames> = {})

Source from the content-addressed store, hash-verified

154 * @__NO_SIDE_EFFECTS__
155 */
156export 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
180export function formatTimeAgo<UnitNames extends string = UseTimeAgoUnitNamesDefault>(from: Date, options: FormatTimeAgoOptions<UnitNames> = {}, now: Date | number = Date.now()): string {
181 const {

Callers 3

index.test.tsFile · 0.90
testSecondFunction · 0.90
component.tsFile · 0.90

Calls 3

useNowFunction · 0.90
getDefaultSchedulerFunction · 0.70
formatTimeAgoFunction · 0.70

Tested by 1

testSecondFunction · 0.72