Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions test/relative-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,14 +523,15 @@ suite('relative-time', function () {
})

test('micro formats years', async () => {
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test name is identical to the [tense=future] suite's micro formats years test later in the file, which can make failures harder to distinguish in test output/search. Renaming to include the tense (e.g., "micro formats years (past)") would make reporting clearer.

Suggested change
test('micro formats years', async () => {
test('micro formats years (past)', async () => {

Copilot uses AI. Check for mistakes.
const datetime = new Date()
datetime.setFullYear(datetime.getFullYear() - 10)
// FIXME: there is still a bug, if the duration is long enough (say, 10 or 100 years)
// then the `month = Math.floor(day / 30)` in elapsedTime causes errors, then "10 years" would output "11y"
Comment on lines +526 to +527
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FIXME/comment calls out the 10-year failure case ("10 years" -> "11y"), but this test now uses a 2-year offset and asserts 2y. Tweaking the comment to explicitly say the test uses a shorter duration to avoid the known long-duration rounding bug would make the intent clearer.

Suggested change
// FIXME: there is still a bug, if the duration is long enough (say, 10 or 100 years)
// then the `month = Math.floor(day / 30)` in elapsedTime causes errors, then "10 years" would output "11y"
// FIXME: there is still a bug if the duration is long enough (say, 10 or 100 years):
// the `month = Math.floor(day / 30)` in elapsedTime causes errors, so "10 years" would output "11y".
// This test intentionally uses a shorter 2-year duration to exercise year micro-formatting ("2y")
// without triggering that known long-duration rounding bug.

Copilot uses AI. Check for mistakes.
const now = new Date(Date.now() - 2 * 365 * 24 * 60 * 60 * 1000).toISOString()
const time = document.createElement('relative-time')
time.setAttribute('tense', 'past')
time.setAttribute('datetime', datetime)
time.setAttribute('datetime', now)
time.setAttribute('format', 'micro')
Comment on lines +528 to 532
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The now variable here is actually the target past datetime being set on the element, not the current time. Renaming it to something like datetime/pastDatetime would make the test easier to follow and reduce confusion with other tests that use now for the current timestamp.

Copilot uses AI. Check for mistakes.
await Promise.resolve()
assert.equal(time.shadowRoot.textContent, '10y')
assert.equal(time.shadowRoot.textContent, '2y')
})

test('micro formats future times', async () => {
Expand Down
Loading