From 5152f5ccfa2523886a88e76dc60f120ec14b2203 Mon Sep 17 00:00:00 2001 From: kwy404 Date: Thu, 22 Oct 2026 13:54:20 -0300 Subject: [PATCH] Fix relative format showing now for any past time under a minute --- src/relative-time-element.ts | 2 +- test/relative-time.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/relative-time-element.ts b/src/relative-time-element.ts index 65cb6e0..620d71a 100644 --- a/src/relative-time-element.ts +++ b/src/relative-time-element.ts @@ -310,7 +310,7 @@ export class RelativeTimeElement extends HTMLElement implements Intl.DateTimeFor if (tense === 'future' && duration.sign !== 1) duration = emptyDuration if (tense === 'past' && duration.sign !== -1) duration = emptyDuration const [int, unit] = getRelativeTimeUnit(duration) - if (unit === 'second' && int < 10) { + if (unit === 'second' && Math.abs(int) < 10) { return relativeFormat.format(0, this.precision === 'millisecond' ? 'second' : this.precision) } return relativeFormat.format(int, unit) diff --git a/test/relative-time.js b/test/relative-time.js index 8b24e74..e2aef56 100644 --- a/test/relative-time.js +++ b/test/relative-time.js @@ -1701,13 +1701,13 @@ suite('relative-time', function () { datetime: '2022-10-24T14:45:10.000Z', tense: 'past', format: 'relative', - expected: 'now', + expected: '50 seconds ago', }, { datetime: '2022-10-24T14:45:10.000Z', format: 'relative', formatStyle: 'narrow', - expected: 'now', + expected: '50s ago', }, { datetime: '2022-10-24T14:45:10.000Z',