Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add tests for C1 and support for six-digit years.

commit 273b9ef58e32d21a1a151fec2ef7902f42553c73 1 parent f38f021
Jason Davies authored

Showing 2 changed files with 24 additions and 2 deletions. Show diff stats Hide diff stats

  1. +7 2 moment.js
  2. +17 0 test/moment/create.js
9 moment.js
@@ -30,7 +30,7 @@
30 30 aspNetJsonRegex = /^\/?Date\((\-?\d+)/i,
31 31
32 32 // format tokens
33   - formattingTokens = /(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|SS?S?|zz?|ZZ?)/g,
  33 + formattingTokens = /(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|YYYYY|YYYY|YY|a|A|hh?|HH?|mm?|ss?|SS?S?|zz?|ZZ?|-)/g,
34 34 localFormattingTokens = /(LT|LL?L?L?)/g,
35 35 formattingRemoveEscapes = /(^\[)|(\\)|\]$/g,
36 36
@@ -42,6 +42,7 @@
42 42 parseTokenOneToThreeDigits = /\d{1,3}/, // 0 - 999
43 43 parseTokenThreeDigits = /\d{3}/, // 000 - 999
44 44 parseTokenFourDigits = /\d{4}/, // 0000 - 9999
  45 + parseTokenFiveToSixDigits = /[+\-]?\d{5,6}/, // -999,999 - 999,999
45 46 parseTokenWord = /[0-9a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+/i, // any word characters or numbers
46 47 parseTokenTimezone = /Z|[\+\-]\d\d:?\d\d/i, // +00:00 -00:00 +0000 -0000 or Z
47 48 parseTokenT = /T/i, // T (ISO seperator)
@@ -104,6 +105,7 @@
104 105 w : '(a=new Date(t.year(),t.month(),t.date()-t.day()+5),b=new Date(a.getFullYear(),0,4),a=~~((a-b)/864e5/7+1.5))',
105 106 YY : 'p(t.year()%100,2)',
106 107 YYYY : 'p(t.year(),4)',
  108 + YYYYY: 'p(t.year(),5)',
107 109 a : 'm(t.hours(),t.minutes(),!0)',
108 110 A : 'm(t.hours(),t.minutes(),!1)',
109 111 H : 't.hours()',
@@ -402,6 +404,8 @@
402 404 return parseTokenThreeDigits;
403 405 case 'YYYY':
404 406 return parseTokenFourDigits;
  407 + case 'YYYYY':
  408 + return parseTokenFiveToSixDigits;
405 409 case 'S':
406 410 case 'SS':
407 411 case 'SSS':
@@ -474,7 +478,8 @@
474 478 datePartArray[0] = input + (input > 70 ? 1900 : 2000);
475 479 break;
476 480 case 'YYYY' :
477   - datePartArray[0] = ~~Math.abs(input);
  481 + case 'YYYYY' :
  482 + datePartArray[0] = ~~input;
478 483 break;
479 484 // AM / PM
480 485 case 'a' : // fall through to A
17 test/moment/create.js
@@ -294,5 +294,22 @@ exports.create = {
294 294 test.equal(moment(null), null, "Calling moment(null)");
295 295 test.equal(moment('', 'YYYY-MM-DD'), null, "Calling moment('', 'YYYY-MM-DD')");
296 296 test.done();
  297 + },
  298 +
  299 + "first century" : function(test) {
  300 + test.expect(2);
  301 + test.equal(moment([0, 0, 1]).format("YYYY-MM-DD"), "0000-01-01", "Year AD 0");
  302 + test.equal(moment([99, 0, 1]).format("YYYY-MM-DD"), "0099-01-01", "Year AD 99");
  303 + test.done();
  304 + },
  305 +
  306 + "six digit years" : function(test) {
  307 + test.expect(5);
  308 + test.equal(moment([-270000, 0, 1]).format("YYYYY-MM-DD"), "-270000-01-01", "format BC 270,000");
  309 + test.equal(moment([ 270000, 0, 1]).format("YYYYY-MM-DD"), "270000-01-01", "format AD 270,000");
  310 + test.equal(moment("-270000-01-01", "YYYYY-MM-DD").toDate().getUTCFullYear(), -270000, "parse BC 270,000");
  311 + test.equal(moment("270000-01-01", "YYYYY-MM-DD").toDate().getUTCFullYear(), 270000, "parse AD 270,000");
  312 + test.equal(moment("+270000-01-01", "YYYYY-MM-DD").toDate().getUTCFullYear(), 270000, "parse AD +270,000");
  313 + test.done();
297 314 }
298 315 };

0 comments on commit 273b9ef

Please sign in to comment.
Something went wrong with that request. Please try again.