gr2m / moment-parseformat

A moment.js plugin to extract the format of a date/time string
http://gr2m.github.io/moment-parseformat
Apache License 2.0
45 stars 30 forks source link

Should default to leading 0's #24

Closed tgrrtt closed 9 years ago

tgrrtt commented 9 years ago

So I was looking through the regex's and realized that it will only parse timestamps as having a leading 0 if there's an explicit leading 0.

/0\d:\d{2}:\d{2}/

Now this means that it will correctly parse something like 01:33:47 as HH:mm:ss However once it goes above that to 12:33:47, it will parse that out as H:mm:ss which is technically correct, as at this point there's no way to know if the timestamp would or would not have a leading 0.

However, I would say that assuming a leading 0 in these caes should be the default, as that is more commonly used with timestamps, and a not leading zero should be the one that is explicitly set, ie any timestamp like 12:34:56 parses out as HH:mm:ss and the only way to get something as H:mm:ss would be to have a match with something like 1:23:45.

gr2m commented 9 years ago

yeah it's somewhat an edge case. moment.parseFormat has been made with humans entering a date in a free text inputs in mind, so UTC and other timestamp standard formats or not a priority. There is no right or wrong here, but I think having a leading zero is something I want to be added only when wanted explicitly.

gr2m commented 9 years ago

I'll close this issue for the sake of oversight. But happy to keep discussing / reopening it, if there are any new arguments pro / contra