Skip to content

Change month microformat from "m" to "mo" in narrow style formatting and fix micro format tense logic - #321

Merged
francinelucca merged 6 commits into
mainfrom
copilot/fix-320
Aug 26, 2025
Merged

Change month microformat from "m" to "mo" in narrow style formatting and fix micro format tense logic#321
francinelucca merged 6 commits into
mainfrom
copilot/fix-320

Conversation

CopilotAI commented Aug 26, 2025

Copy link
Copy Markdown
Contributor

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 fixformat.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 fixformat.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-timedatetime="2022-09-24T14:46:00.000Z"tense="future"format="micro">// "1mo"<relative-timedatetime="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.

CopilotAI commented Aug 26, 2025

Copy link
Copy Markdown
ContributorAuthor

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

CopilotAIand others added 2 commits August 26, 2025 02:12
Co-authored-by: francinelucca <40550942+francinelucca@users.noreply.github.com>
Co-authored-by: francinelucca <40550942+francinelucca@users.noreply.github.com>
CopilotAI changed the title [WIP] change month microformat from "m" to "mo"Change month microformat from "m" to "mo" in narrow style formattingAug 26, 2025
@francinelucca

Copy link
Copy Markdown
Contributor

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

Co-authored-by: francinelucca <40550942+francinelucca@users.noreply.github.com>

CopilotAI commented Aug 26, 2025

Copy link
Copy Markdown
ContributorAuthor

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

@francinelucca

Copy link
Copy Markdown
Contributor

@copilot fix test errors

Co-authored-by: francinelucca <40550942+francinelucca@users.noreply.github.com>

CopilotAI commented Aug 26, 2025

Copy link
Copy Markdown
ContributorAuthor

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

CopilotAI changed the title Change month microformat from "m" to "mo" in narrow style formattingChange month microformat from "m" to "mo" in narrow style formatting and fix micro format tense logicAug 26, 2025
@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 ownerAugust 26, 2025 04:20
CopilotAI review requested due to automatic review settings August 26, 2025 04:20

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 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
FileDescription
src/duration-format-ponyfill.tsAdded custom handling to replace "m" with "mo" for month units in narrow style
src/relative-time-element.tsFixed micro format tense logic to allow month-level durations to display with mismatched tense
test/duration-format-ponyfill.tsAdded test for complex duration showing months as "1mo" and minutes as "3m"
test/relative-time.jsUpdated test expectations for month-related cases and added new micro format test
README.mdUpdated 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.

Comment threadtest/relative-time.js
@@ -561,6 +561,17 @@ suite('relative-time', function () {
await Promise.resolve()

CopilotAIAug 26, 2025

Copy link

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
Copy Markdown

I can't believe Copilot fixed this, amazing!

@hectahertzhectahertz left a comment

Copy link
Copy Markdown

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 mainAug 26, 2025
4 checks passed
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.

change month microformat from "m" to "mo"

4 participants

@francinelucca@hectahertz