-
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
Allow ISO-8601 to be passed as a format. #1693
Conversation
This commit allows the ISO-8601 format to be passed as a format in the moment(string, array) constructor. This is a preliminary commit as this addition as yielded a few issues.
I've added a useFallback parameter to makeDateFromString. When not supplied, the old behavior remains. When supplied and true, it does not call the createFromInputCallback and instead returns an empty config. This also seems to fix the first issue, it now plays much nicer with scoring and precendence.
I've added much more relevant tests, checking the _f property for the format that was used for parsing and _pf.iso in the case of ISO.
This seems to be working properly, now. It also seems like it didn't break anything else. Let me know if you want me to add more tests or if you think that something won't work properly. |
var i, l, | ||
string = config._i, | ||
match = isoRegex.exec(string); | ||
|
||
useFallback = typeof useFallback === 'undefined' ? true : useFallback; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useFallback == null
should be enough here (check for null
or undefined
).
I I think its good in general. Just please extract the parsing iso part into a separate function. |
`moment.js` now has a separate parseISO function which only handles the parsing. `makeDateFromString` keeps the same behavior and uses parseISO. The tests have also been refactored and moved into their own function.
Should I also update the docs to document this? |
Thanks, that looks great. About docs you can make a pr at the momentjs.com repo. I do docs changes on release in general but you're welcome to help. |
Allow ISO-8601 to be passed as a format. @changelog @section features @description support moment.ISO_8601 as a format in constructor, that would use ISO time format parsing
This commit allows the ISO-8601 format to be passed as a format in the moment(string, array) constructor. This is an attempt to make #1680 possible.This is a preliminary commit as this addition as yielded a few issues. This is not ready for merge.
Here are some of the issues:
makeDateFromString
does not play nice with scoring (might be due to the way I implemented it)makeDateFromString
shoves what it doesn't know into intocreateFromInputFallback
which has been modified to throw always throw an error in the test suite.I will probably try to add an optional parameter to
makeDateFromString
which tells it to not usecreateFromInputFallback
to fix the second issue.