Skip to content

docs: add RelativeTime component and formatRelativeTime docs#182

Open
moss-bryophyta wants to merge 4 commits intomainfrom
docs/relative-time
Open

docs: add RelativeTime component and formatRelativeTime docs#182
moss-bryophyta wants to merge 4 commits intomainfrom
docs/relative-time

Conversation

@moss-bryophyta
Copy link
Copy Markdown
Collaborator

Adds documentation for the new <RelativeTime> component and formatRelativeTime/formatRelativeTimeFromDate functions introduced in generaltranslation/gt#1153.

What's included

  • Template: docs-templates/api/components/relativetime.mdx — shared template for gt-next and gt-react
  • Next.js docs: Auto-generated stub at docs/en-US/next/api/components/relativetime.mdx
  • React docs: Auto-generated stub at docs/en-US/react/api/components/relativetime.mdx
  • Core standalone functions:
    • formatRelativeTime — explicit value + unit formatting
    • formatRelativeTimeFromDate — auto-selects unit from a Date
  • Core class methods: Same two functions as GT class methods
  • Navigation: All relevant meta.json files updated

Component overview

The <RelativeTime> component has two modes:

  • Auto: <RelativeTime>{someDate}</RelativeTime> → "2 hours ago"
  • Explicit: <RelativeTime value={-1} unit="day" /> → "yesterday"

No Python docs added — the PR only covers JS/React packages.

- Add template for RelativeTime component (gt-next, gt-react)
- Add auto-generated stubs for next and react docs
- Add core standalone function docs for formatRelativeTime and formatRelativeTimeFromDate
- Add core class method docs for formatRelativeTime and formatRelativeTimeFromDate
- Update all relevant meta.json navigation files

Covers PR generaltranslation/gt#1153
@moss-bryophyta moss-bryophyta requested a review from a team as a code owner March 26, 2026 22:51
@moss-bryophyta moss-bryophyta enabled auto-merge (squash) March 26, 2026 22:51
@moss-bryophyta
Copy link
Copy Markdown
Collaborator Author

Re-evaluated against the implementation in gt. Found one factual issue:

numeric default is 'auto', not 'always'

In _formatRelativeTime (core), the defaults are { style: 'long', numeric: 'auto', ...options }. But all four formatting docs say the default is 'always'. This also makes the "Default numeric: 'always'" examples wrong — e.g. formatRelativeTimeFromDate(yesterday, { locales: 'en-US' }) would actually return "yesterday", not "1 day ago".

Also minor: the template calls Intl.RelativeTimeFormat a "library" — it's a built-in API.

Will push fixes now.

@archie-mckenzie
Copy link
Copy Markdown
Collaborator

@greptile-ai review

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