// FORMATTING
+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;
+ }
+});
+
addFormatToken(0, ['YY', 2], 0, function () {
return this.year() % 100;
});
addParseToken('YY', function (input, array) {
array[YEAR] = hooks.parseTwoDigitYear(input);
});
+addParseToken('Y', function (input, array) {
+ array[YEAR] = parseInt(input, 10);
+});
// HELPERS
assert.equal(moment('112345', 'Hmmss', true).format('HH:mm:ss'), '11:23:45', '112345 with Hmmss');
assert.equal(moment('172345', 'Hmmss', true).format('HH:mm:ss'), '17:23:45', '112345 with Hmmss');
});
+
+test('Y token', function (assert) {
+ assert.equal(moment('1-1-2010', 'M-D-Y', true).year(), 2010, 'parsing Y');
+});
assert.equal(moment('08:34:56', 'HH:mm:ss').format('Hmmss'), '83456');
assert.equal(moment('18:34:56', 'HH:mm:ss').format('Hmmss'), '183456');
});
+
+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');
+});