Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: use Intl.DateTimeFormatter instead of toLocaleTimeString #13951

Merged
merged 1 commit into from Jul 25, 2023

Conversation

patak-dev
Copy link
Member

Description

Follow up to #13949. This seems to be the only place left where we are using toLocale directly.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

@stackblitz
Copy link

stackblitz bot commented Jul 25, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@patak-dev patak-dev added the performance Performance related enhancement label Jul 25, 2023
@patak-dev patak-dev merged commit af53a1d into main Jul 25, 2023
20 checks passed
@patak-dev patak-dev deleted the perf/use-date-time-formatter branch July 25, 2023 16:43
@@ -77,7 +82,7 @@ export function createLogger(
: type === 'warn'
? colors.yellow(colors.bold(prefix))
: colors.red(colors.bold(prefix))
return `${colors.dim(new Date().toLocaleTimeString())} ${tag} ${msg}`
return `${colors.dim(timeFormatter.format(new Date()))} ${tag} ${msg}`
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems that new Date() can be omitted. 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks like that is the case, docs are not clear on MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/format. Maybe better to leave it explicit?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, I didn't find the documentation clearly stating whether it is optional or not. Only the ts hint is optional, as you said, it should be better to keep it as it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance related enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants