relative-time-element
relative-time-element copied to clipboard
Wrong human text
I'm supposing this is the code that writes dates on Github web front.
1 year ago, it writes "2 years ago"
Same issue on https://github.com/grayjoking/backhand (flagged up by user):
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
I have a refactor PR that’ll be ready soon which will resolve these without regressing the other cases we’ve run into.
@keithamus currently I am trying to dive into the code. Could you please point me to the PR with the refactoring?
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.