+import hasOwnProp from '../utils/has-own-prop';
import toInt from '../utils/to-int';
import indexOf from '../utils/index-of';
import {Duration} from './constructor';
export default function isDurationValid(m) {
for (var key in m) {
- if (!(indexOf.call(ordering, key) !== -1 && (m[key] == null || !isNaN(m[key])))) {
+ if (hasOwnProp(m, key) && !(indexOf.call(ordering, key) !== -1 && (m[key] == null || !isNaN(m[key])))) {
return false;
}
}
export function set (config) {
var prop, i;
for (i in config) {
- prop = config[i];
- if (isFunction(prop)) {
- this[i] = prop;
- } else {
- this['_' + i] = prop;
+ if (hasOwnProp(config, i)) {
+ prop = config[i];
+ if (isFunction(prop)) {
+ this[i] = prop;
+ } else {
+ this['_' + i] = prop;
+ }
}
}
this._config = config;
+import hasOwnProp from '../utils/has-own-prop';
+
var priorities = {};
export function addUnitPriority(unit, priority) {
export function getPrioritizedUnits(unitsObj) {
var units = [];
for (var u in unitsObj) {
- units.push({unit: u, priority: priorities[u]});
+ if (hasOwnProp(unitsObj, u)) {
+ units.push({unit: u, priority: priorities[u]});
+ }
}
units.sort(function (a, b) {
return a.priority - b.priority;
import extend from './extend';
import { hooks } from './hooks';
+import hasOwnProp from './has-own-prop';
function warn(msg) {
if (hooks.suppressDeprecationWarnings === false &&
if (typeof arguments[i] === 'object') {
arg += '\n[' + i + '] ';
for (var key in arguments[0]) {
- arg += key + ': ' + arguments[0][key] + ', ';
+ if (hasOwnProp(arguments[0], key)) {
+ arg += key + ': ' + arguments[0][key] + ', ';
+ }
}
arg = arg.slice(0, -2); // Remove trailing comma and space
} else {
import { test } from '../qunit';
-import each from './each';
-import objectKeys from './object-keys';
+import eachOwnProp from './each-own-prop';
import moment from '../../moment';
-import defaults from '../../lib/utils/defaults';
export function defineCommonLocaleTests(locale, options) {
test('lenient day of month ordinal parsing', function (assert) {
});
test('date format correctness', function (assert) {
- var data, tokens;
- data = moment.localeData()._longDateFormat;
- tokens = objectKeys(data);
- each(tokens, function (srchToken) {
+ var data = moment.localeData()._longDateFormat;
+ eachOwnProp(data, function (srchToken) {
// Check each format string to make sure it does not contain any
// tokens that need to be expanded.
- each(tokens, function (baseToken) {
+ eachOwnProp(data, function (baseToken) {
// strip escaped sequences
var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
assert.equal(false, !!~format.indexOf(srchToken),
--- /dev/null
+import each from './each';
+import objectKeys from './object-keys';
+
+function eachOwnProp(object, callback) {
+ each(objectKeys(object), callback);
+}
+
+export default eachOwnProp;
import { module, test } from '../qunit';
+import eachOwnProp from '../helpers/each-own-prop';
import moment from '../../moment';
module('create');
'Mon, 02 Jan 2017 06:00:00 EDT': [2017, 0, 2, 6, 0, 0, -4 * 60]
};
- var inp, tokens, parseResult, expResult;
-
- for (inp in testCases) {
- tokens = testCases[inp];
- parseResult = moment(inp, moment.RFC_2822, true).parseZone();
- expResult = moment.utc(tokens.slice(0, 6)).utcOffset(tokens[6], true);
+ eachOwnProp(testCases, function (inp) {
+ var tokens = testCases[inp],
+ parseResult = moment(inp, moment.RFC_2822, true).parseZone(),
+ expResult = moment.utc(tokens.slice(0, 6)).utcOffset(tokens[6], true);
assert.ok(parseResult.isValid(), inp);
assert.ok(parseResult.parsingFlags().rfc2822, inp + ' - rfc2822 parsingFlag');
assert.equal(parseResult.utcOffset(), expResult.utcOffset(), inp + ' - zone');
assert.equal(parseResult.valueOf(), expResult.valueOf(), inp + ' - correctness');
- }
+ });
});
test('non RFC 2822 strings', function (assert) {
'RFC2822 datetime with all options but invalid day delimiter': 'Tue. 01 Nov 2016 01:23:45 GMT',
'RFC2822 datetime with mismatching Day (weekday v date)': 'Mon, 01 Nov 2016 01:23:45 GMT'
};
- var testCase;
- for (testCase in testCases) {
+ eachOwnProp(testCases, function (testCase) {
var testResult = moment(testCases[testCase], moment.RFC_2822, true);
assert.ok(!testResult.isValid(), testCase + ': ' + testResult + ' - is invalid rfc2822');
assert.ok(!testResult.parsingFlags().rfc2822, testCase + ': ' + testResult + ' - rfc2822 parsingFlag');
- }
+ });
});
test('parsing RFC 2822 in a different locale', function (assert) {
'clean RFC2822 datetime with single-digit day-of-month': 'Tue, 1 Nov 2016 06:23:45 GMT',
'RFC2822 datetime with CFWSs': '(Init Comment) Tue,\n 1 Nov 2016 (Split\n Comment) 07:23:45 +0000 (GMT)'
};
- var testCase;
try {
moment.locale('ru');
- for (testCase in testCases) {
+ eachOwnProp(testCases, function (testCase) {
var testResult = moment(testCases[testCase], moment.RFC_2822, true);
assert.ok(testResult.isValid(), testResult);
assert.ok(testResult.parsingFlags().rfc2822, testResult + ' - rfc2822 parsingFlag');
- }
+ });
}
finally {
moment.locale('en');
'RFC2822 datetime with all options but invalid day delimiter': 'Tue. 01 Nov 2016 01:23:45 GMT',
'RFC2822 datetime with mismatching Day (week v date)': 'Mon, 01 Nov 2016 01:23:45 GMT'
};
- var testCase;
try {
moment.locale('ru');
- for (testCase in testCases) {
+ eachOwnProp(testCases, function (testCase) {
var testResult = moment(testCases[testCase], moment.RFC_2822, true);
assert.ok(!testResult.isValid(), testResult);
assert.ok(!testResult.parsingFlags().rfc2822, testResult + ' - rfc2822 parsingFlag');
- }
+ });
}
finally {
moment.locale('en');
import { module, test } from '../qunit';
import each from '../helpers/each';
+import eachOwnProp from '../helpers/each-own-prop';
import moment from '../../moment';
module('format');
'2010-01-03': '2009-53',
'404-12-31': '0404-53',
'405-12-31': '0405-52'
- }, i, isoWeek, formatted2, formatted1;
+ };
- for (i in cases) {
+ eachOwnProp(cases, function (i) {
+ var isoWeek, formatted2, formatted1;
isoWeek = cases[i].split('-').pop();
formatted2 = moment(i, 'YYYY-MM-DD').format('WW');
assert.equal(isoWeek, formatted2, i + ': WW should be ' + isoWeek + ', but ' + formatted2);
isoWeek = isoWeek.replace(/^0+/, '');
formatted1 = moment(i, 'YYYY-MM-DD').format('W');
assert.equal(isoWeek, formatted1, i + ': W should be ' + isoWeek + ', but ' + formatted1);
- }
+ });
});
test('iso week year formats', function (assert) {
'2010-01-03': '2009-53',
'404-12-31': '0404-53',
'405-12-31': '0405-52'
- }, i, isoWeekYear, formatted5, formatted4, formatted2;
+ };
- for (i in cases) {
+ eachOwnProp(cases, function (i) {
+ var isoWeekYear, formatted5, formatted4, formatted2;
isoWeekYear = cases[i].split('-')[0];
formatted5 = moment(i, 'YYYY-MM-DD').format('GGGGG');
assert.equal('0' + isoWeekYear, formatted5, i + ': GGGGG should be ' + isoWeekYear + ', but ' + formatted5);
assert.equal(isoWeekYear, formatted4, i + ': GGGG should be ' + isoWeekYear + ', but ' + formatted4);
formatted2 = moment(i, 'YYYY-MM-DD').format('GG');
assert.equal(isoWeekYear.slice(2, 4), formatted2, i + ': GG should be ' + isoWeekYear + ', but ' + formatted2);
- }
+ });
});
test('week year formats', function (assert) {
'2010-01-03': '2009-53',
'404-12-31': '0404-53',
'405-12-31': '0405-52'
- }, i, isoWeekYear, formatted5, formatted4, formatted2;
+ };
moment.defineLocale('dow:1,doy:4', {week: {dow: 1, doy: 4}});
- for (i in cases) {
+ eachOwnProp(cases, function (i) {
+ var isoWeekYear, formatted5, formatted4, formatted2;
isoWeekYear = cases[i].split('-')[0];
formatted5 = moment(i, 'YYYY-MM-DD').format('ggggg');
assert.equal('0' + isoWeekYear, formatted5, i + ': ggggg should be ' + isoWeekYear + ', but ' + formatted5);
assert.equal(isoWeekYear, formatted4, i + ': gggg should be ' + isoWeekYear + ', but ' + formatted4);
formatted2 = moment(i, 'YYYY-MM-DD').format('gg');
assert.equal(isoWeekYear.slice(2, 4), formatted2, i + ': gg should be ' + isoWeekYear + ', but ' + formatted2);
- }
+ });
moment.defineLocale('dow:1,doy:4', null);
});
});
// test('full expanded format is returned from abbreviated formats', function (assert) {
-// function objectKeys(obj) {
-// if (Object.keys) {
-// return Object.keys(obj);
-// } else {
-// // IE8
-// var res = [], i;
-// for (i in obj) {
-// if (obj.hasOwnProperty(i)) {
-// res.push(i);
-// }
-// }
-// return res;
-// }
-// }
// var locales =
// 'ar-sa ar-tn ar az be bg bn bo br bs ca cs cv cy da de-at de dv el ' +
// 'sr sv sw ta te th tl-ph tlh tr tzl tzm-latn tzm uk uz vi zh-cn zh-tw';
// each(locales.split(' '), function (locale) {
-// var data, tokens;
-// data = moment().locale(locale).localeData()._longDateFormat;
-// tokens = objectKeys(data);
-// each(tokens, function (token) {
+// var data = moment().locale(locale).localeData()._longDateFormat;
+// eachOwnProp(data, function (token) {
// // Check each format string to make sure it does not contain any
// // tokens that need to be expanded.
// each(tokens, function (i) {
import { module, test } from '../qunit';
+import each from '../helpers/each';
import moment from '../../moment';
module('is valid');
moment([2100, 0, 32]),
moment.utc([2010, 0, 0]),
moment.utc([2100, 0, 32])
- ],
- i, m;
+ ];
- for (i in tests) {
- m = tests[i];
+ each(tests, function (m) {
assert.equal(m.isValid(), false);
- }
+ });
});
test('h/hh with hour > 12', function (assert) {