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

v4: option extraFormats to improve parsing #666

Merged
merged 2 commits into from Nov 25, 2014

Conversation

Koloto
Copy link

@Koloto Koloto commented Nov 24, 2014

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 the datetimepicker too. So I introduced an option extraFormats - 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:

{
    format: 'DD.MM.YYYY',
    extraFormats: [ 'DD.MM.YY' ]
}

According to the documentation moment "prefers formats earlier in the array than later":

moment('1.1.1', [ 'DD.MM.YYYY', 'DD.MM.YY' ]); // 0001-01-01 - not clear
moment('1.1.1', [ 'DD.MM.YY', 'DD.MM.YYYY' ]); // 2001-01-01 - correct

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 into extraFormats at any index, e.g.:

{
    format: 'DD.MM.YYYY',
    extraFormats: [ 'DD.MM.YYYY', 'DD.MM.YY' ]
}

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

Eonasdan added a commit that referenced this pull request Nov 25, 2014
v4: option extraFormats to improve parsing
@Eonasdan Eonasdan merged commit 97476d9 into Eonasdan:v4beta Nov 25, 2014
@Koloto Koloto deleted the v4/extraFormats branch December 2, 2014 10:50
kikonen pushed a commit to kikonen/bootstrap-datetimepicker that referenced this pull request Jan 2, 2017
Repository owner locked and limited conversation to collaborators Jun 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants