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

Add lightFormat and optimize size of toDate (closes #1010) #1015

Merged
merged 2 commits into from Dec 13, 2018

Conversation

kossnocorp
Copy link
Member

From #1010:

format is one of the most (if not the most) popular function in date-fns, but because it involves locales it's one the most (if not the most) heavyweight function in date-fns.

Given that v2 locales became even more heavyweight, I want to introduce lightFormat that will cover the most common cases and address the size problem.

The current goal is to be able to print ISO 8601 plus hh representing 12-hour clock and a..aaa representing am/pm.

This PR:

  • Introduces lightFormat described in the quote above. The current function size is 1.73 KB.
  • Optimizes toDatesize from 1.48 KB to 1.27 KB.

Unfortunately, it's not possible to bring the size significantly down. The bottleneck is toDate function and specifically the code responsible for parsing ISO 8601 strings.

src/lightFormat/index.js Outdated Show resolved Hide resolved
Copy link
Contributor

@leshakoss leshakoss left a comment

Choose a reason for hiding this comment

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

Nice! Great job!

@kossnocorp kossnocorp merged commit 9b0d043 into master Dec 13, 2018
@kossnocorp kossnocorp deleted the 1010-light-format branch December 13, 2018 11:33
@kossnocorp kossnocorp mentioned this pull request Dec 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants