Skip to content

fix(util): format collapsibleDate time without locale dependency#1603

Open
WolfieLeader wants to merge 2 commits intoarktypeio:mainfrom
WolfieLeader:fix/collapsible-date-locale-independent
Open

fix(util): format collapsibleDate time without locale dependency#1603
WolfieLeader wants to merge 2 commits intoarktypeio:mainfrom
WolfieLeader:fix/collapsible-date-locale-independent

Conversation

@WolfieLeader
Copy link
Copy Markdown

Summary

Fixes #1494

describeCollapsibleDate() called date.toLocaleTimeString() which produces 24-hour format on non-US systems, causing garbled output like "14:30, January 15, 2023" instead of "2:30 PM, January 15, 2023".

Replaced with locale-independent manual formatting using getHours(), getMinutes(), getSeconds():

  • hours % 12 || 12 for correct 12-hour conversion (midnight→12, noon→12)
  • hours < 12 ? " AM" : " PM" for suffix
  • Reuses existing pad() helper
  • Removed now-unused timeWithUnnecessarySeconds regex (caught by eslint no-unused-vars)

Test plan

  • All 8 existing collapsibleDate tests pass unchanged (year-only, day, minutes, seconds, milliseconds, midnight, noon, AM/PM)
  • Verified all edge cases: midnight (h=0→12 AM), noon (h=12→12 PM), hour boundaries
  • pnpm prChecks passes (format, lint, typecheck, full test suite)

Copy link
Copy Markdown
Contributor

@pullfrog pullfrog bot left a comment

Choose a reason for hiding this comment

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

Clean, correct fix. The hours % 12 || 12 idiom handles all edge cases (midnight→12 AM, noon→12 PM), and conditionally building the time string is simpler than the previous approach of calling toLocaleTimeString() then stripping/rewriting parts of its output. The timeWithUnnecessarySeconds regex removal is a natural consequence. No issues found.

Pullfrog  | View workflow runpullfrog.com𝕏

@WolfieLeader
Copy link
Copy Markdown
Author

Awesome pullfrog!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To do

Development

Successfully merging this pull request may close these issues.

collapsibleDate tests fail on 24-hour clock

1 participant