Skip to content

Add micro tense phrasing#355

Open
maxbeizer wants to merge 2 commits into
mb/micro-explicit-thresholdfrom
mb/micro-tense-phrasing
Open

Add micro tense phrasing#355
maxbeizer wants to merge 2 commits into
mb/micro-explicit-thresholdfrom
mb/micro-tense-phrasing

Conversation

@maxbeizer
Copy link
Copy Markdown

@maxbeizer maxbeizer commented Jun 2, 2026

Summary

This builds on #354 by making format="micro" useful with explicit tense. Instead of forcing consumers to append their own ago suffix or in prefix, micro output now uses localized Intl.RelativeTimeFormat narrow phrasing.

Behavior after this PR:

  • format="micro" tense="past" renders values like 2w ago
  • format="micro" tense="future" renders values like in 3d
  • tense="auto" keeps the existing compact output like 2w
  • datetime fallback and user-preferred absolute-time output are not wrapped with tense text

Closes #353

Tests

  • npm test
  • npm run lint

Copilot AI review requested due to automatic review settings June 2, 2026 21:19
@maxbeizer maxbeizer requested a review from a team as a code owner June 2, 2026 21:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds “micro” tense phrasing support so format="micro" can render localized narrow relative strings (e.g., “2w ago”, “in 3d”) when tense="past|future", while preserving the existing compact micro output when tense="auto". This also tightens format="micro" behavior around explicit threshold and the user “prefers absolute time” override.

Changes:

  • Add a micro-specific relative formatter path using Intl.RelativeTimeFormat(..., {style: 'narrow'}) for tense="past" / tense="future".
  • Ensure format="micro" honors threshold only when the attribute is explicitly provided (otherwise preserves legacy behavior).
  • Add/adjust tests and README docs for micro tense/threshold/user-preference behavior.
Show a summary per file
File Description
src/relative-time-element.ts Implements micro tense phrasing via Intl.RelativeTimeFormat when tense is past/future and keeps tense=auto compact output; includes explicit-threshold handling for micro.
test/relative-time.js Adds coverage for micro threshold/date fallback, micro tense=auto compact behavior, localized micro tense phrasing, and absolute-time preference interactions.
README.md Documents the new micro tense behavior and updates the tense behavior table to include format=micro.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 3/3 changed files
  • Comments generated: 2

Comment thread README.md Outdated
Comment thread test/relative-time.js
@maxbeizer maxbeizer force-pushed the mb/micro-tense-phrasing branch 5 times, most recently from 2c40f65 to 39c45ff Compare June 2, 2026 22:13
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@maxbeizer maxbeizer force-pushed the mb/micro-tense-phrasing branch from 39c45ff to 9b4a607 Compare June 2, 2026 22:21
}

#getMicroRelativeFormat(duration: Duration): string {
const relativeFormat = new Intl.RelativeTimeFormat(this.#lang, {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This uses Intl.RelativeTimeFormat rather than string-concatenating English ago / in, so the compact tense output still follows lang.

} else {
if (format === 'duration') {
newText = this.#getDurationFormat(duration)
if (this.format === 'micro' && this.tense !== 'auto' && Intl.RelativeTimeFormat) {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The tense phrasing is intentionally limited to micro duration output. Datetime fallback from #354 and user-preferred absolute output bypass this path, so we do not produce strings like Jan 1, 2024 ago.

Comment thread test/relative-time.js
assert.equal(time.shadowRoot.textContent, 'hace 3 días')
})

test('micro tense phrasing respects lang attribute', async () => {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This is the guard against accidentally making the feature English-only: the micro tense path should localize through Intl.RelativeTimeFormat.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants