Skip to content

Experimental feature: Support absolute time format - #327

Merged
zaataylor merged 8 commits into
mainfrom
tiny-wins-absolute-time-setting
Oct 22, 2025
Merged

Experimental feature: Support absolute time format#327
zaataylor merged 8 commits into
mainfrom
tiny-wins-absolute-time-setting

Conversation

@khiga8

@khiga8khiga8 commented Oct 21, 2025

Copy link
Copy Markdown
Contributor

Relates to: https://github.com/github/fixing-oss-pain-points/issues/148

Warning

This is an experimental feature. It may be modified or removed at any time!

This PR adds support for rendering absolute time format if the consumer has a data-prefers-absolute-time attribute on the body or html tag, set to true.

return `${this.prefix} ${formatter.format(date)}`.trim()
}

#getUserPreferredAbsoluteTimeFormat(date: Date): string {

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.

For now, matching the title format.

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.

For other potential reviewers, here's an example of what this looks like: Oct 23, 2025 6:59 AM EDT


#shouldDisplayUserPreferredAbsoluteTime(format: ResolvedFormat): boolean {
// Never override duration format with absolute format.
if (format === 'duration') return false

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.

I think... this makes sense? @zaataylor check me on this :D

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.

This makes sense! 🫡 This will also work for elapsed format since they're aliases

// elapsed is an alias for 'duration'
if(format==='elapsed')return'duration'

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.

Oh and for micro, too:

// 'micro' is an alias for 'duration'
if(format==='micro')return'duration'

Comment on lines +248 to +249
this.ownerDocument.documentElement.getAttribute('data-prefers-absolute-time') === 'true' ||
this.ownerDocument.body?.getAttribute('data-prefers-absolute-time') === 'true'

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.

adding support for body and html, based on @dgreif comment

staff only: slack

@khiga8
khiga8 marked this pull request as ready for review October 21, 2025 18:39
@khiga8
khiga8 requested a review from a team as a code ownerOctober 21, 2025 18:39
CopilotAI review requested due to automatic review settings October 21, 2025 18:39

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

This PR introduces an experimental feature to support absolute time formatting based on user preference. When the data-prefers-absolute-time attribute is set to "true" on either the html or body element, relative time elements will display in absolute format instead of relative format.

Key Changes:

  • Added logic to detect and respect the data-prefers-absolute-time preference from document or body elements
  • Implemented absolute time formatting with locale-aware date/time display
  • Added comprehensive test coverage for the new feature including edge cases

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

FileDescription
src/relative-time-element.tsImplements the core absolute time formatting logic and preference detection
test/relative-time.jsAdds test suite covering various scenarios for the absolute time feature
package.jsonReorders lint commands to run TypeScript checks before ESLint

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment threadsrc/relative-time-element.ts

@zaataylorzaataylor 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.

Overall, these changes look good to me!

return `${this.prefix} ${formatter.format(date)}`.trim()
}

#getUserPreferredAbsoluteTimeFormat(date: Date): string {

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.

For other potential reviewers, here's an example of what this looks like: Oct 23, 2025 6:59 AM EDT


#shouldDisplayUserPreferredAbsoluteTime(format: ResolvedFormat): boolean {
// Never override duration format with absolute format.
if (format === 'duration') return false

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.

This makes sense! 🫡 This will also work for elapsed format since they're aliases

// elapsed is an alias for 'duration'
if(format==='elapsed')return'duration'


#shouldDisplayUserPreferredAbsoluteTime(format: ResolvedFormat): boolean {
// Never override duration format with absolute format.
if (format === 'duration') return false

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.

Oh and for micro, too:

// 'micro' is an alias for 'duration'
if(format==='micro')return'duration'

@zaataylor
zaataylor merged commit 00f47f8 into mainOct 22, 2025
4 checks passed
@khiga8
khiga8 deleted the tiny-wins-absolute-time-setting branch October 22, 2025 17:07
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.

5 participants

@khiga8@dgreif@zaataylor@francinelucca