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

fix(gatsby): added looksLikeADate to check date on schema creation #12722

Merged
merged 3 commits into from
Mar 25, 2019

Conversation

wardpeet
Copy link
Contributor

@wardpeet wardpeet commented Mar 21, 2019

Description

Moment.js is slow at parsing dates so this PR does a lot of extra validation before we fallback to moment. I copied some code from moment.js to parse the ISO formats and do a quick regex myself.

Build Schema on www now is 2s on my machine instead of 60s before.

Checks that are being done:

  1. is it a number?
  2. does the length of the value comply with any of our formats
  3. does the str starts with 4 digites (YYYY)
  4. does the str ends with something that looks like a date
  5. Small regex to see if it matches any of the defined ISO formats
  6. check momentjs

Related Issues

#12692

@wardpeet wardpeet changed the title fix(gatsby): add some quickchecks to isDate fix(gatsby): added looksLikeADate to check date on schema creation Mar 22, 2019
@wardpeet
Copy link
Contributor Author

ok so I couldn't get the isDate checks to work how it should. Momentjs does checks for validation of dates like 30 february will never be true but 29 might be. So i added an extra function that checks if it looks like a date which is not bullet proof but probably good enough for schema creation.

@freiksenet
Copy link
Contributor

Thank you Ward!

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