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

Add format and parse token Y, so it actually works #2868

Closed
wants to merge 2 commits into
base: develop
from

Conversation

Projects
None yet
2 participants
@ichernev
Contributor

ichernev commented Jan 6, 2016

Fix #2859

@mj1856 mj1856 added this to the 2.11.1 milestone Jan 6, 2016

} else {
// force plus for longer years.
return '+' + y;
}

This comment has been minimized.

@mj1856

mj1856 Jan 6, 2016

Member

This could just be return y < 1e4 ? y : '+' + y;

Also, do we need to always return a string, and do years between 0 and 999 need to be zero-padded to 4-digits? (not sure)

@@ -36,6 +48,9 @@ addParseToken('YYYY', function (input, array) {
addParseToken('YY', function (input, array) {
array[YEAR] = hooks.parseTwoDigitYear(input);
});
addParseToken('Y', function (input, array) {
array[YEAR] = parseInt(input, 10);

This comment has been minimized.

@mj1856

mj1856 Jan 6, 2016

Member

Anything wrong with input | 0, or are we wanting to be verbose and let ES6->ES5 transpilation do those tricks? (I suppose same for above comment)

This comment has been minimized.

@ichernev

ichernev Jan 9, 2016

Contributor

parseInt is the canonical way to do this. I don't want to act as an uglifier, the code is ugly enough already :)

assert.equal(moment('2010-01-01', 'YYYY-MM-DD', true).format('Y'), '2010', 'format 2010 with Y');
assert.equal(moment('-123-01-01', 'Y-MM-DD', true).format('Y'), '-123', 'format -123 with Y');
assert.equal(moment('12345-01-01', 'Y-MM-DD', true).format('Y'), '+12345', 'format 12345 with Y');
});

This comment has been minimized.

@mj1856

mj1856 Jan 6, 2016

Member

Also test years 0, 1, 9999, 10000

ichernev added a commit that referenced this pull request Jan 9, 2016

Merge pull request #2868 from ichernev:fix-y-token
Add format and parse token Y, so it actually works
@ichernev

This comment has been minimized.

Contributor

ichernev commented Jan 9, 2016

Merged in 74141ae

@ichernev ichernev closed this Jan 9, 2016

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