}
//if the day of the year is set, figure out what it is
- if (config._dayOfYear) {
+ if (config._dayOfYear != null) {
yearToUse = defaults(config._a[YEAR], currentDate[YEAR]);
- if (config._dayOfYear > daysInYear(yearToUse)) {
+ if (config._dayOfYear > daysInYear(yearToUse) || config._dayOfYear === 0) {
getParsingFlags(config)._overflowDayOfYear = true;
}
export var match1to4 = /\d{1,4}/; // 0 - 9999
export var match1to6 = /[+-]?\d{1,6}/; // -999999 - 999999
-export var match1to3nonzero = /[1-9]\d{0,2}|\d[1-9]\d{0,1}|\d{0,2}[1-9]/; // 1 - 999
-export var match3nonzero = /[1-9]\d\d|\d[1-9]\d|\d\d[1-9]/; // 001 - 999
-
export var matchUnsigned = /\d+/; // 0 - inf
export var matchSigned = /[+-]?\d+/; // -inf - inf
import { addFormatToken } from '../format/format';
import { addUnitAlias } from './aliases';
import { addUnitPriority } from './priorities';
-import { addRegexToken, match3nonzero, match1to3nonzero } from '../parse/regex';
+import { addRegexToken, match3, match1to3 } from '../parse/regex';
import { daysInYear } from './year';
import { createUTCDate } from '../create/date-from-array';
import { addParseToken } from '../parse/token';
// PARSING
-addRegexToken('DDD', match1to3nonzero);
-addRegexToken('DDDD', match3nonzero);
+addRegexToken('DDD', match1to3);
+addRegexToken('DDDD', match3);
addParseToken(['DDD', 'DDDD'], function (input, array, config) {
config._dayOfYear = toInt(input);
});
--- /dev/null
+import { module, test } from '../qunit';
+import moment from '../../moment';
+
+module('days in year');
+
+// https://github.com/moment/moment/issues/3717
+test('YYYYDDD should not parse DDD=000', function (assert) {
+ assert.equal(moment(7000000, moment.ISO_8601, true).isValid(), false);
+ assert.equal(moment('7000000', moment.ISO_8601, true).isValid(), false);
+ assert.equal(moment(7000000, moment.ISO_8601, false).isValid(), false);
+});
+++ /dev/null
-import { module, test } from '../qunit';
-import moment from '../../moment';
-import {match1to3nonzero} from '../../lib/parse/regex';
-
-module('regex');
-
-test('match1to3nonzero works properly', function (assert) {
- assert.equal('0'.match(match1to3nonzero), null);
- assert.equal('00'.match(match1to3nonzero), null);
- assert.equal('000'.match(match1to3nonzero), null);
-
- for (var i = 1; i < 1000; i++) {
- assert.notEqual(String(i).match(match1to3nonzero), null);
- if (i < 100) {
- assert.notEqual('0' + String(i).match(match1to3nonzero), null);
- if (i < 10) {
- assert.notEqual('00' + String(i).match(match1to3nonzero), null);
- }
- }
- }
-});
-
-// https://github.com/moment/moment/issues/3717
-test('YYYYDDD should not parse DDD=000 (strict mode)', function (assert) {
- assert.equal(moment(7000000, moment.ISO_8601, true).isValid(), false);
- assert.equal(moment('7000000', moment.ISO_8601, true).isValid(), false);
-});
-
-// https://github.com/moment/moment/issues/3717
-test('YYYYDDD will parse DDD=000 (non-strict mode)', function (assert) {
- assert.equal(moment(7000000, moment.ISO_8601, false).isValid(), true);
- assert.equal(moment(7000000, moment.ISO_8601, false)._pf.unusedTokens.length, 1);
- assert.equal(moment(7000000, moment.ISO_8601, false)._pf.unusedTokens[0], 'DDD');
-});