diff --git a/packages/core/useTimeAgo/index.test.ts b/packages/core/useTimeAgo/index.test.ts index a9d516c106a..e21af69cc52 100644 --- a/packages/core/useTimeAgo/index.test.ts +++ b/packages/core/useTimeAgo/index.test.ts @@ -249,6 +249,15 @@ describe('useTimeAgo', () => { expect(useTimeAgo(changeTime, { rounding: 3 }).value).toBe('in 5.49 days') }) + test('rounding unit fallback', () => { + changeValue.value = getNeededTimeChange('month', 11.5) + expect(useTimeAgo(changeTime).value).toBe('next year') + expect(useTimeAgo(changeTime, { rounding: 'ceil' }).value).toBe('next year') + expect(useTimeAgo(changeTime, { rounding: 'floor' }).value).toBe('in 11 months') + expect(useTimeAgo(changeTime, { rounding: 1 }).value).toBe('in 0.9 year') + expect(useTimeAgo(changeTime, { rounding: 3 }).value).toBe('in 0.945 year') + }) + test('custom units', () => { changeValue.value = getNeededTimeChange('day', 14) expect(useTimeAgo(changeTime).value).toBe('in 2 weeks') diff --git a/packages/core/useTimeAgo/index.ts b/packages/core/useTimeAgo/index.ts index 5b53735452a..844358565f0 100644 --- a/packages/core/useTimeAgo/index.ts +++ b/packages/core/useTimeAgo/index.ts @@ -168,8 +168,12 @@ export function foramtTimeAgo 0 const str = applyFormat(unit.name as UnitNames, val, past) @@ -196,7 +200,10 @@ export function foramtTimeAgo