Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

tux-tn
Copy link
Member

@tux-tn tux-tn commented Aug 8, 2020

Hello,

I made some changes to isDate to allow for more flexibility.

  • Add strictMode to enforce strict comparison between input and format. In strictMode Date objects, inputs with a different delimiter or string format are disallowed.
  • Disallow validating inputs with mixed delimiters (Fixes Bug in Date validation, isDate() function #1395 )
  • Allow passing custom delimiters list
  • This PR is backward compatible with old format isDate(input, format)

Checklist

  • PR contains only changes related; no stray files, etc.
  • README updated (where applicable)
  • Tests written (where applicable)

@codecov
Copy link

codecov bot commented Aug 8, 2020

Codecov Report

Merging #1402 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master     #1402   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           95        95           
  Lines         1248      1257    +9     
=========================================
+ Hits          1248      1257    +9     
Impacted Files Coverage Δ
src/lib/isDate.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ed86b0a...1f9833e. Read the comment docs.

@tux-tn
Copy link
Member Author

tux-tn commented Aug 8, 2020

strictModeis based on @ezkemboi idea in #1395 but with few changes. After some research, i can't find a standard date format with mixed delimiters and i don't think that allowing it in #1270 was purposely. For this reason strictMode intent here is to prevent validating inputs different from format.

validator.isDate('2020-05-02', { format: 'YYYY/MM/DD', strictMode: true}); /// returns false
validator.isDate(new Date(), { format: 'YYYY/MM/DD', strictMode: true}); // returns false

@ezkemboi
Copy link
Member

ezkemboi commented Aug 8, 2020

@tux-tn thanks for working on this.
Cc. @profnandaa

Copy link
Member

@profnandaa profnandaa left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the good work on this. I'm okay at some point down the line, making strictMode = true the default -- but for now, this is okay to maintain b/c.

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.

Bug in Date validation, isDate() function

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.