Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 26, 2025

Closes #320, https://github.com/github/primer/issues/5575
This PR resolves the ambiguity in narrow style formatting where both months and minutes were displayed as "m", making it difficult for users and assistive technologies to distinguish between the two units.

Problem

In the narrow style formatting (formatStyle: 'narrow'), both months and minutes used the same abbreviation "m":

// Before this fix
format.format(Duration.from('P1M'))   // "1m" (1 month)
format.format(Duration.from('PT1M'))  // "1m" (1 minute)

This created confusion, especially for screen readers which might interpret "1m" as "1 meter" instead of the intended time unit.

Additionally, the micro format had a bug where month-level durations with mismatched tense (e.g., past dates with tense="future") would incorrectly fall back to displaying "1m" (1 minute) instead of the actual month duration "1mo".

Solution

Months now use "mo" while minutes continue to use "m", and the micro format properly displays month durations regardless of tense mismatches:

// After this fix
format.format(Duration.from('P1M'))   // "1mo" (1 month)
format.format(Duration.from('PT1M'))  // "1m" (1 minute)
format.format(Duration.from('P1M2D')) // "1mo 2d"
format.format(Duration.from('PT1M30S')) // "1m 30s"
format.format(Duration.from('P1M2DT3M30S')) // "1mo 2d 3m 30s"

// Micro format with tense mismatches now works correctly
<relative-time datetime="2022-09-24T14:46:00.000Z" tense="future" format="micro"> // "1mo"
<relative-time datetime="2022-11-24T14:46:00.000Z" tense="past" format="micro">   // "1mo"

Changes Made

  • src/duration-format-ponyfill.ts: Added custom handling in formatToParts() to replace "m" with "mo" for month units in narrow style
  • src/relative-time-element.ts: Fixed micro format tense logic to allow month-level durations to display properly even with mismatched tense
  • test/duration-format-ponyfill.ts: Added test for P1M2DT3M30S duration showing months as "1mo" and minutes as "3m" in narrow style
  • test/: Updated test expectations for month-related cases to expect "mo" instead of "m"
  • README.md: Updated documentation table to reflect the new narrow format example

Impact

  • ✅ Eliminates ambiguity between months and minutes
  • ✅ Improves accessibility for screen readers
  • ✅ Maintains backward compatibility for all other units
  • ✅ Only affects narrow style month formatting
  • ✅ Fixes micro format edge cases with tense mismatches
  • ✅ Added test coverage for complex durations with both months and minutes

Fixes #320.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copy link
Contributor Author

Copilot AI commented Aug 26, 2025

@francinelucca 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

@Copilot Copilot AI changed the title [WIP] change month microformat from "m" to "mo" Change month microformat from "m" to "mo" in narrow style formatting Aug 26, 2025
@Copilot Copilot AI requested a review from francinelucca August 26, 2025 02:15
Copilot finished work on behalf of francinelucca August 26, 2025 02:15
@francinelucca
Copy link
Contributor

@copilot add test for a time duration that includes months and minutes, for example P1M2D3M30S

Copy link
Contributor Author

Copilot AI commented Aug 26, 2025

@copilot add test for a time duration that includes months and minutes, for example P1M2D3M30S

Added test for duration P1M2DT3M30S that includes both months and minutes. The test verifies that months display as "1mo" and minutes as "3m" in narrow style formatting, confirming the fix eliminates the ambiguity between the two units. See commit 7bf7225.

Copilot finished work on behalf of francinelucca August 26, 2025 02:54
@francinelucca
Copy link
Contributor

@copilot fix test errors

Copy link
Contributor Author

Copilot AI commented Aug 26, 2025

@copilot fix test errors

Fixed the test errors. The issue was with the micro format tense checking logic that was causing month-level durations to fall back to minute display instead of showing the actual month duration. Updated the logic to allow month durations to pass through even with mismatched tense. All 578 tests now pass. See commit eeade77.

@Copilot Copilot AI changed the title Change month microformat from "m" to "mo" in narrow style formatting Change month microformat from "m" to "mo" in narrow style formatting and fix micro format tense logic Aug 26, 2025
Copilot finished work on behalf of francinelucca August 26, 2025 03:22
@francinelucca francinelucca marked this pull request as ready for review August 26, 2025 04:20
@francinelucca francinelucca requested a review from a team as a code owner August 26, 2025 04:20
@Copilot Copilot AI review requested due to automatic review settings August 26, 2025 04:20
Copy link
Contributor

@Copilot 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

This PR resolves the ambiguity in narrow style formatting where both months and minutes were displayed as "m", making it difficult for users and assistive technologies to distinguish between the two units. The change updates months to use "mo" while minutes continue to use "m", and fixes the micro format to properly display month durations regardless of tense mismatches.

  • Changed month abbreviation from "m" to "mo" in narrow style formatting to eliminate confusion with minutes
  • Fixed micro format tense logic to allow month-level durations to display properly even with mismatched tense
  • Updated tests and documentation to reflect the new month abbreviation

Reviewed Changes

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

Show a summary per file
File Description
src/duration-format-ponyfill.ts Added custom handling to replace "m" with "mo" for month units in narrow style
src/relative-time-element.ts Fixed micro format tense logic to allow month-level durations to display with mismatched tense
test/duration-format-ponyfill.ts Added test for complex duration showing months as "1mo" and minutes as "3m"
test/relative-time.js Updated test expectations for month-related cases and added new micro format test
README.md Updated documentation table to reflect new narrow format example

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

@@ -561,6 +561,17 @@ suite('relative-time', function () {
await Promise.resolve()
Copy link
Preview

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

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

Copilot detected a code snippet with 1 occurrences. See search results for more details.

Matched Code Snippet
relative-time')
      time.setAttribute('tense', 'past')
      time.setAttribute('datetime', datetime)
      time.setAttribute('format', 'micro')
      await Promise.resolve()
      assert.equal(time.shadowRoot.textContent,

Copilot uses AI. Check for mistakes.

@hectahertz
Copy link

I can't believe Copilot fixed this, amazing!

Copy link

@hectahertz hectahertz left a comment

Choose a reason for hiding this comment

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

Seems consistent with our approach, looks good!

@francinelucca francinelucca merged commit 69bd240 into main Aug 26, 2025
4 checks passed
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.

change month microformat from "m" to "mo"
3 participants