-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
'H' format string broken in strict parsing #1401
Comments
You're right. We made strict parsing a bit too strict in the last version. |
Hmm, did we? If H eats 2 tokens whenever possible, that will lead to broken parses: moment('3141113', 'HDDMMYY', true).format(); //=> '2013-11-14T03:00:00-05:00'
moment('3141113', 'HHDDMMYY', true).format(); //=> 'Invalid date' That's a big part of why we made strict act the way it does. (Of course, the real solution would be to use a global regex so we get backtracking, but that's a separate discussion) More generally, why even have "H" and "HH" if they're the same? |
Well, we have |
Meaning, you're proposing that in strict mode, I'm OK with that, but it won't allow you to roundtrip I think maybe the best thing to do would be to eliminate |
@icambron I see two types of issues here. The year family of tokens (
So I suggest
This behavior is kind of different than the formatting behavior, but I think it has the least amount of surprise for most users. Because most users use regular years, and YY and YYYY make sense for them. The second issue is with all other tokens (h, H, d, D, M, s, w, W..., DDD). These can be mostly one or two digits, and only padding is changed with the different formatting tokens. I think if you want rock solid parsing, you'd use So I propose:
|
But one can neither use
So what would you suggest? |
|
@ichernev I think that's what I said too. I just wanted to clarify that you won't be able to guarantee round tripping. It sounds like you're OK with that and only intend moment(moment().hours(1).format('HDD'), 'HDD', true); //WHY YOU NO WORK? If you're OK with answering that with "dude, use HH", then I'm good with it too. |
Well, you're shooting yourself in the foot with that code IMHO. So yeah :) Btw the initial implementation of strict would have worked here -- because it first builds the entire regex, and the second token would be |
Right, the advantage of a global regex is that we get backtracking and we don't have to deal with greed as much. |
I hit an unexpected error when using 'H' to parse 24h-time values without a leading zero:
I would expect
H
to be usable here, so that the code can also work with times before noon.The text was updated successfully, but these errors were encountered: