Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Fix parsing/formatting of first century dates. #366

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants
Contributor

jasondavies commented Jul 17, 2012

According to ECMA-262, new Date(y, …) will auto-convert y to 1900 + y if 0 ≤ y ≤ 99, hence setFullYear or setUTCFullYear is used instead.

This also zero-pads the year for the "YYYY" format, since the year may not necessarily have four digits.

@jasondavies jasondavies Fix parsing/formatting of first century dates.
According to ECMA-262, `new Date(y, …)` will auto-convert `y` to `1900 +
y` if `0 ≤ y ≤ 99`, hence setFullYear or setUTCFullYear is used instead.

This also zero-pads the year for the "YYYY" format, since the year may
not necessarily have four digits.
71b4e1f
Owner

timrwood commented Jul 17, 2012

Wow, this looks nice.

I think this should be safe to merge in. I hope no-one was relying on moment([0]) being Jan 1 1900...

In theory, moment([-100, 0, 1]) should work as well now, no?

Also, you should work off the develop branch as that has the latest code, and some of the code you wrote will need to be re-written. For example, the internal function dateFromArray now takes an asUTC parameter so the rest of the codebase isn't littered with config.isUTC ? new Date(Date.UTC.apply({}, datePartArray)) : dateFromArray(datePartArray);. Instead, it's return dateFromArray(datePartArray, config.isUTC);

https://github.com/timrwood/moment/blob/c018776284d0bcd9b3a4e67160336ff7b85915ae/moment.js#L270

Also, there was some stuff added so that moment.fn.isValid would work on parsed strings and array input.

I'm going to close this PR, but please create a new one based on the develop branch and submit the PR to the develop branch.

Thanks for contributing!

@timrwood timrwood closed this Jul 17, 2012

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