import isArray from '../utils/is-array';
+import isObject from '../utils/is-object';
+import isObjectEmpty from '../utils/is-object-empty';
import isDate from '../utils/is-date';
import map from '../utils/map';
import { createInvalid } from './valid';
strict = locale;
locale = undefined;
}
+
+ if ((isObject(input) && isObjectEmpty(input)) ||
+ (isArray(input) && input.length === 0)) {
+ input = undefined;
+ }
// object construction must be done this way.
// https://github.com/moment/moment/issues/1423
c._isAMomentObject = true;
};
try {
- assert.ok(moment().toISOString() === customTimeStr, 'moment() constructor should use the function defined by moment.now, but it did not');
- assert.ok(moment.utc().toISOString() === customTimeStr, 'moment() constructor should use the function defined by moment.now, but it did not');
- assert.ok(moment.utc([]).toISOString() === '2015-01-01T00:00:00.000Z', 'moment() constructor should fall back to the date defined by moment.now when an empty array is given, but it did not');
+ assert.equal(moment().toISOString(), customTimeStr, 'moment() constructor should use the function defined by moment.now, but it did not');
+ assert.equal(moment.utc().toISOString(), customTimeStr, 'moment() constructor should use the function defined by moment.now, but it did not');
} finally {
moment.now = oldFn;
}
});
+
+test('empty object, empty array', function (assert) {
+ function assertIsNow(gen, msg) {
+ var before = +(new Date),
+ mid = gen(),
+ after = +(new Date);
+ assert.ok(before <= +mid && +mid <= after, 'should be now : ' + msg);
+ }
+ assertIsNow(function () { return moment(); }, 'moment()');
+ assertIsNow(function () { return moment([]); }, 'moment([])');
+ assertIsNow(function () { return moment({}); }, 'moment({})');
+ assertIsNow(function () { return moment.utc(); }, 'moment.utc()');
+ assertIsNow(function () { return moment.utc([]); }, 'moment.utc([])');
+ assertIsNow(function () { return moment.utc({}); }, 'moment.utc({})');
+});