Skip to content

Fix formatPlainTime locale handling and improve test coverage - #46

Merged
zac1st1k merged 7 commits into
mainfrom
bugfix/fix-format-plain-time-nan-error
Jul 20, 2026
Merged

Fix formatPlainTime locale handling and improve test coverage#46
zac1st1k merged 7 commits into
mainfrom
bugfix/fix-format-plain-time-nan-error

Conversation

@zac1st1k

Copy link
Copy Markdown
Collaborator

Summary

  • Fix formatPlainTime returning "NaN:NaN:NaN" under dd/mm/yyyy runtime locales (e.g. en-GB) when the day is > 12, by pinning the locale used in its toLocaleString round-trip to en-US.
  • Run the test suite under both en-US and en-GB (test:en-US / test:en-GB, both invoked by npm test) to catch this class of locale regression going forward.
  • Add regression coverage for the day > 12 case, and fix a duration assertion that silently relied on the runtime's default locale.
  • Whitelist published files via package.json#files (drop .npmignore), and verify the npm pack output against that whitelist in index.dist.test.ts.
  • Bump dev dependencies (eslint, jest, typescript, webpack, etc.) to latest.

Test plan

  • npm run test:en-US
  • npm run test:en-GB
  • npm run lint

@zac1st1k
zac1st1k force-pushed the bugfix/fix-format-plain-time-nan-error branch from 53f73f6 to 077471a Compare July 20, 2026 03:58
@zac1st1k
zac1st1k force-pushed the bugfix/fix-format-plain-time-nan-error branch from 077471a to ab2c858 Compare July 20, 2026 04:13
@zac1st1k
zac1st1k requested review from JakeLDev, aaaa0441 and jdyAt July 20, 2026 04:15

@JakeLDev JakeLDev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

😁👍🏻

Comment thread src/index.ts
}

export function formatPlainTime(date = new Date(), timeZone = getTimeZone()) {
const timeZonedDate = new Date(date.toLocaleString(undefined, { timeZone }));

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This function is not pure when the parameter is undefined. The returned date string can depend on browser user settings.

@zac1st1k zac1st1k changed the title Fix locale handling and improve test coverage for date formatting Fix formatPlainTime locale handling and improve test coverage Jul 20, 2026
@zac1st1k
zac1st1k merged commit 124d239 into main Jul 20, 2026
5 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.

3 participants