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 exact digits patterns (#916) #3729

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

yesl-kim
Copy link

@yesl-kim yesl-kim commented Mar 12, 2024

description

comment

  • I feagured out that the original flexible digit patterns (twoDigits, threeDigits, fourDigits) are pretty universally used, including y and Y, as well as the thing kind of mm.
  • It seems that a new pattern needs to be added to make the y, Y format also check the digit strictly as they said in the issue.
  • But first of all, I wanted to ask your opinion, so I modified only the pattern of mm, ss, and hh format that people need the most in that issue.
  • Do you agree to be revised in this direction?

Plus

  • In moment.js, strictly can be chosen with a third argument.
moment('04:3:00', 'HH:mm:ss', true) // strict
moment('04:3:00', 'HH:mm:ss') // not strict

  • I think it's better for backward compatibility
  • what do think of it?

@kossnocorp
Copy link
Member

I like where it's going! Strict parsing is one of the most requested features, and I want to see it addressed. The way to go is to hide it behind the strict option and make it strict in the next major version by default.

Feel free to complete the PR by adding the option and expanding the approach to the rest of the numeric tokens!

- add strict digits patterns and utils
- strictly parse the digits according to the options

fixed date-fns#916
@yesl-kim
Copy link
Author

@kossnocorp Thank you for comment!

changes

  • Added new patterns and utils for strict mode
    • minNDigits: specifies only padding (eg. yyy -> 001, 012, 123, 1234, ...)
    • exactNDigits: specifies the maximum length as well as padding
  • Modified it to parse strictly as options

comment

  • Normally used minNDigits pattern since the validate method is checking the range of values.
  • Tested all tokens I modified but wrote the part of them randomly since they're mostly the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: WIP
Development

Successfully merging this pull request may close these issues.

Correct way to validate time
3 participants