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

date mm parser expects zero based months #128

Closed
groner opened this issue May 23, 2013 · 7 comments
Closed

date mm parser expects zero based months #128

groner opened this issue May 23, 2013 · 7 comments

Comments

@groner
Copy link

groner commented May 23, 2013

I'm not sure if this was intended, but it would be nice if it could work with iso8601 dates.

Running this:

picker = jQuery($0).data('pickadate');
picker.set('select', '2013-01-01', {format: 'yyyy-mm-dd'});
picker.get();

Yields this:

"1 February, 2013"

But I expected this:

"1 January, 2013"

Thanks!

@amsul
Copy link
Owner

amsul commented May 23, 2013

Although undocumented, you can already do this. It’s used internally to parse the data-value attribute by passing a truth-y data option:

picker = jQuery($0).data('pickadate');
picker.set('select', '2013-01-01', {format: 'yyyy-mm-dd', data: true});
picker.get();

This should parse as the expected date.

I’ll leave this issue open till I update the docs.

Cheers!

@groner
Copy link
Author

groner commented May 23, 2013

I did come across that code, but it seemed like an internal detail I shouldn't rely on.

I am curious though, is there something that uses zero based months in formatted strings?

@amsul
Copy link
Owner

amsul commented Jun 10, 2013

Do you mean to ask if there is any case where the zero-based months are used to generate a string value of the date?

The zero-based months are mostly to keep inline with what people expect from native Date objects. It’s also much easier to deal with zero-based months when you have an array of month names that starts with 0 as the index.

@amsul
Copy link
Owner

amsul commented Jun 10, 2013

Oh and yes, it is for internal use - but I wont be changing it so I guess it's safe to use.

@boxofrad
Copy link

Hey @amsul,
Other than ease of implementation is there a design reason you opted for zero based months?
As @groner mentioned it makes it quite irritating when using ISO 8601 formatted dates, and also behaves differently to JavaScript's native date parsing.

new Date('2013-01-01') // Tue Jan 01 2013 00:00:00 GMT+0000 (GMT)

Perhaps an alternative would be to give a format string of "iso8601" that adheres to the standard instead, like so:

picker.set('select', '2013-01-01', { format: 'iso8601' });

Would you accept a pull request adding this?

@amsul
Copy link
Owner

amsul commented Jan 31, 2014

@boxofrad yup, that’s right. The native date parser does work that way.

Rather than the need to pass iso8601, I believe the parser should be fixed. It should check for the value as a string and compensate for the month’s index. This will be fixed in the next release.

Cheers!

@amsul amsul closed this as completed in ce813fd Feb 15, 2014
denis-sokolov added a commit to SlikNL/pickadate.js that referenced this issue Mar 5, 2014
denis-sokolov added a commit to SlikNL/pickadate.js that referenced this issue Mar 5, 2014
denis-sokolov added a commit to SlikNL/pickadate.js that referenced this issue Mar 5, 2014
denis-sokolov added a commit to SlikNL/pickadate.js that referenced this issue Mar 5, 2014
@GoZOo
Copy link

GoZOo commented Mar 24, 2014

e4c91cc commit fix this. Whithout @denis-sokolov commit, default input value like 2014-03-24 show wrong month in calendar (April).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants