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

"hh" token prevents date from strict parsing when the hour value is 0 #5857

Open
Earthwormzim opened this issue Mar 24, 2021 · 0 comments
Open

Comments

@Earthwormzim
Copy link

Earthwormzim commented Mar 24, 2021

If you do a strict parse of a date where the format specified has the 'hh' token in it and the hour part of the date-to-be-parsed is '00', moment will report it as an invalid date

To Reproduce
Steps to reproduce the behavior:

  1. Go here: https://replit.com/@sabbyjiang/Moment-Playground (or do it in your own Node env)
  2. Type the following lines into the terminal and press enter:
moment('March, 24 2021 00:00:00', 'MMMM, DD YYYY hh:mm:ss', true);
moment('March, 24 2021 01:00:00', 'MMMM, DD YYYY hh:mm:ss', true);

Expected behavior
Both of those examples should be accepted as valid dates.

It appears that in moment.js, at approximately line #158, the validity of the date is dependent upon setting bigHour to undefined.

if (m._strict) {
   isNowValid = isNowValid && flags.charsLeftOver === 0 && flags.unusedTokens.length === 0 && flags.bigHour === undefined;
}

At apprimately line #2529, you have a block of code that looks like this:

if (config._a[HOUR] <= 12 && getParsingFlags(config).bigHour === true && config._a[HOUR] > 0) {
      getParsingFlags(config).bigHour = undefined;
}

It looks like 0 should be included in the range so that bigHour will get set to undefined, i.e., the code should look like this:

if (config._a[HOUR] <= 12 && getParsingFlags(config).bigHour === true && config._a[HOUR] >= 0) {
      getParsingFlags(config).bigHour = undefined;
}

Screenshots
image

Desktop (please complete the following information):

  • OS: Windows 10
  • Chrome Version 89.0.4389.90
  • Moment Version 2.29.1
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

No branches or pull requests

1 participant