Skip to content

Add micro tense phrasing - #355

Merged
liuliu-dev merged 2 commits into
mb/micro-explicit-thresholdfrom
mb/micro-tense-phrasing
Jun 5, 2026
Merged

Add micro tense phrasing#355
liuliu-dev merged 2 commits into
mb/micro-explicit-thresholdfrom
mb/micro-tense-phrasing

Conversation

@maxbeizer

@maxbeizermaxbeizer commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

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

CopilotAI review requested due to automatic review settings June 2, 2026 21:19
@maxbeizer
maxbeizer requested a review from a team as a code ownerJune 2, 2026 21:19

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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
FileDescription
src/relative-time-element.tsImplements 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.jsAdds coverage for micro threshold/date fallback, micro tense=auto compact behavior, localized micro tense phrasing, and absolute-time preference interactions.
README.mdDocuments 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 threadREADME.md Outdated
Comment threadtest/relative-time.js
@maxbeizer
maxbeizerforce-pushed the mb/micro-tense-phrasing branch 5 times, most recently from 2c40f65 to 39c45ffCompareJune 2, 2026 22:13
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@maxbeizer
maxbeizerforce-pushed the mb/micro-tense-phrasing branch from 39c45ff to 9b4a607CompareJune 2, 2026 22:21
}

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

Copy link
Copy Markdown
ContributorAuthor

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
ContributorAuthor

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 threadtest/relative-time.js
assert.equal(time.shadowRoot.textContent, 'hace 3 días')
})

test('micro tense phrasing respects lang attribute', async () => {

Copy link
Copy Markdown
ContributorAuthor

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.

@liuliu-dev
liuliu-dev merged commit 9d6dd68 into mb/micro-explicit-thresholdJun 5, 2026
@maxbeizer
maxbeizer deleted the mb/micro-tense-phrasing branch June 5, 2026 20:32
@liuliu-devliuliu-dev mentioned this pull request Jun 9, 2026
Sign up for freeto 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.

3 participants

@maxbeizer@liuliu-dev