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

Allow ISO-8601 to be passed as a format. #1693

Merged
merged 4 commits into from
Jun 12, 2014
Merged

Allow ISO-8601 to be passed as a format. #1693

merged 4 commits into from
Jun 12, 2014

Conversation

sbstp
Copy link
Contributor

@sbstp sbstp commented Jun 3, 2014

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)
  • scoring cannot currently be tested because makeDateFromString shoves what it doesn't know into into createFromInputFallback 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 use createFromInputFallback to fix the second issue.

@sbstp sbstp changed the title Allow ISO-8601 to be passed a format. Allow ISO-8601 to be passed as a format. Jun 3, 2014
sbstp added 3 commits June 3, 2014 11:42
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.
@sbstp
Copy link
Contributor Author

sbstp commented Jun 3, 2014

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;
Copy link
Contributor

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).

@ichernev
Copy link
Contributor

ichernev commented Jun 5, 2014

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.
@sbstp
Copy link
Contributor Author

sbstp commented Jun 5, 2014

Should I also update the docs to document this?

@ichernev
Copy link
Contributor

ichernev commented Jun 5, 2014

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.

ichernev added a commit that referenced this pull request Jun 12, 2014
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
@ichernev ichernev merged commit 31e9f8a into moment:develop Jun 12, 2014
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

Successfully merging this pull request may close these issues.

None yet

2 participants