v4: option extraFormats to improve parsing #666
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
moment
supports an array of formats to parse. I think it's a good idea to support several 'parse' formats and one 'output' format in thedatetimepicker
too. So I introduced an optionextraFormats
- an array of optional formats which can be used while parsing.format
option specify output format and it is also used as the last parse format. Why the last? For example I want to display four-digit year but also support two-digit year. I specify the following options:According to the documentation
moment
"prefers formats earlier in the array than later":So we must place longer formats at the end of array.
I suppose output format is typically the longest. But if someone wants to change this logic he can add
format
value intoextraFormats
at any index, e.g.:I also looked at #616: there the first element of array is always used as output format. I think it's incorrect in many cases (see example above).
P.S. Sorry for my English:)