relative-time-element icon indicating copy to clipboard operation
relative-time-element copied to clipboard

Wrong human text

Open antonio-fr opened this issue 2 years ago • 5 comments

I'm supposing this is the code that writes dates on Github web front.

1 year ago, it writes "2 years ago" image

antonio-fr avatar Feb 11 '23 12:02 antonio-fr

Same issue on https://github.com/grayjoking/backhand (flagged up by user):

image

turbo avatar Feb 14 '23 09:02 turbo

Here’s a test case that illustrates the issue:

--- a/test/relative-time.js
+++ b/test/relative-time.js
@@ -2411,18 +2411,18 @@ suite('relative-time', function () {
         expected: 'in 3 years',
       },
       {
-        reference: '2022-12-31T12:00:00.000Z',
-        datetime: '2024-03-01T12:00:00.000Z',
-        tense: 'future',
-        format: 'micro',
-        expected: '3y',
+        reference: '2023-02-18T19:00:00.000Z',
+        datetime: '2021-02-02T20:49:31.000Z',
+        tense: 'past',
+        format: 'auto',
+        expected: '2 years ago',
       },
       {
-        reference: '2021-04-24T12:00:00.000Z',
-        datetime: '2023-02-01T12:00:00.000Z',
-        tense: 'future',
-        format: 'micro',
-        expected: '2y',
+        reference: '2023-02-18T19:00:00.000Z',
+        datetime: '2021-01-23T09:28:06.000Z',
+        tense: 'past',
+        format: 'auto',
+        expected: '2 years ago',
       },
     ])

Output:

test/relative-time.js:

 ❌ relative-time > legacy formats > <relative-time datetime="2021-02-02T20:49:31.000Z" tense="past" format="auto"  > => 2 years ago
      AssertionError: expected '3 years ago' to equal '2 years ago'
      + expected - actual
      
      -3 years ago
      +2 years ago

Might be related to https://github.com/github/relative-time-element/pull/249? cc @keithamus

stapelberg avatar Feb 18 '23 18:02 stapelberg

I have a refactor PR that’ll be ready soon which will resolve these without regressing the other cases we’ve run into.

keithamus avatar Feb 18 '23 22:02 keithamus

@keithamus currently I am trying to dive into the code. Could you please point me to the PR with the refactoring?

Wulfheart avatar Aug 29 '23 13:08 Wulfheart

I did some work on trying to create a polyfill for Temporal Durations so we could move to those but the work stalled due to the complexity of the Temporal APIs. I don't have an active branch or PR so the current code is the latest iteration.

keithamus avatar Aug 29 '23 17:08 keithamus