diff --git a/src/format.test.ts b/src/format.test.ts index cdabb0f..3d793d1 100644 --- a/src/format.test.ts +++ b/src/format.test.ts @@ -258,4 +258,16 @@ describe('format(invalid inputs)', () => { format(-Infinity); }).toThrow(); }); + + it('should handle negative pluralization correctly', () => { + expect(format(-1500, { long: true })).toBe('-1 second'); + expect(format(-1501, { long: true })).toBe('-2 seconds'); + expect(format(-1000, { long: true })).toBe('-1 second'); + }); + + it('should handle positive pluralization correctly', () => { + expect(format(1500, { long: true })).toBe('2 seconds'); + expect(format(1501, { long: true })).toBe('2 seconds'); + expect(format(1000, { long: true })).toBe('1 second'); + }); }); diff --git a/src/index.ts b/src/index.ts index d50e3c7..b1f3df5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -239,6 +239,7 @@ function plural( n: number, name: string, ): StringValue { - const isPlural = msAbs >= n * 1.5; - return `${Math.round(ms / n)} ${name}${isPlural ? 's' : ''}` as StringValue; + const rounded = Math.round(ms / n); + const isPlural = Math.abs(rounded) !== 1; + return `${rounded} ${name}${isPlural ? 's' : ''}` as StringValue; }