From 1159e247d0c99611b538a3291b52409c6007878c Mon Sep 17 00:00:00 2001 From: Iskren Chernev Date: Sat, 9 Jan 2016 11:31:26 +0200 Subject: [PATCH] Apply PR comments --- src/lib/units/year.js | 9 +-------- src/test/moment/format.js | 4 ++++ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/lib/units/year.js b/src/lib/units/year.js index 5244e0c0e..a09e5e3ac 100644 --- a/src/lib/units/year.js +++ b/src/lib/units/year.js @@ -11,14 +11,7 @@ import toInt from '../utils/to-int'; addFormatToken('Y', 0, 0, function () { var y = this.year(); - if (y < 0) { - return y; - } else if (y <= 9999) { - return y; - } else { - // force plus for longer years. - return '+' + y; - } + return y <= 9999 ? '' + y : '+' + y; }); addFormatToken(0, ['YY', 2], 0, function () { diff --git a/src/test/moment/format.js b/src/test/moment/format.js index f20cab2a0..2e6006662 100644 --- a/src/test/moment/format.js +++ b/src/test/moment/format.js @@ -429,4 +429,8 @@ test('Y token', function (assert) { 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'); + assert.equal(moment('0-01-01', 'Y-MM-DD', true).format('Y'), '0', 'format 0 with Y'); + assert.equal(moment('1-01-01', 'Y-MM-DD', true).format('Y'), '1', 'format 1 with Y'); + assert.equal(moment('9999-01-01', 'Y-MM-DD', true).format('Y'), '9999', 'format 9999 with Y'); + assert.equal(moment('10000-01-01', 'Y-MM-DD', true).format('Y'), '+10000', 'format 10000 with Y'); }); -- 2.47.2