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

Zero based dates #28

Closed
kevinrademan opened this issue Mar 12, 2017 · 2 comments
Closed

Zero based dates #28

kevinrademan opened this issue Mar 12, 2017 · 2 comments

Comments

@kevinrademan
Copy link

First up, awesome library. Thanks for all the hard work.

This is more of a usability/understandability issue. Right now dates are being parsed 0 based. This means that the following happens

fecha.parse('2010-02-02', 'YYYY-MM-DD');// 02 March 2010
fecha.parse('2010-03-02', 'YYYY-MM-DD');// 02 April 2010
fecha.parse('2010-04-02', 'YYYY-MM-DD');// 02 May 2010

The documentation seems to suggest that this is expected behavior

fecha.parse('10-12-10 14:11:12', 'YY-MM-DD HH:mm:ss'); // new Date(2010, 11, 10, 14, 11, 12)

As you can imagine this is a land mine for a any developer (including myself) that didn't read the fine print.
My recommendation is that is should parse the dates non-zero based so that its more predictable

@taylorhakes
Copy link
Owner

taylorhakes commented Mar 14, 2017

I am not able to reproduce the issue you are talking about. What browser are you using? I tested in Chrome and got the following results.

fecha.parse('2010-02-02', 'YYYY-MM-DD');// 02 February 2010
fecha.parse('2010-03-02', 'YYYY-MM-DD');// 02 March 2010
fecha.parse('2010-04-02', 'YYYY-MM-DD');// 02 April 2010

Javascript dates are zero based for the month. This library returns a normal javascript Date object. The date.getMonth() returns a zero based month and the javascript Date constructor also expects a zero based month.

// new Date(2010, 11, 10, 14, 11, 12) == December 10, 2010 2:11:12PM
fecha.parse('10-12-10 14:11:12', 'YY-MM-DD HH:mm:ss'); // new Date(2010, 11, 10, 14, 11, 12) 

Here is a link to more info about the javascript Date object. The notes talk about the 0 based month

@taylorhakes
Copy link
Owner

taylorhakes commented Mar 18, 2017

If you are able to reproduce this issue, please reopen this issue

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

No branches or pull requests

2 participants