};
}
+ function deprecate(msg, fn) {
+ var firstTime = true;
+ function printMsg() {
+ if (typeof console !== 'undefined' && console.warn) {
+ console.warn("Deprecation warning: " + msg);
+ }
+ }
+ return extend(function () {
+ if (firstTime) {
+ printMsg();
+ firstTime = false;
+ }
+ return fn.apply(this, arguments);
+ }, fn);
+ }
+
function padToken(func, count) {
return function (a) {
return leftZeroFill(func.call(this, a), count);
makeDateFromStringAndFormat(config);
}
else {
- config._d = new Date(string);
+ config._d = moment.createFromInputFallback(string);
}
}
var input = config._i,
format = config._f;
- if (input === null) {
+ if (input === null || (format === undefined && input === '')) {
return moment.invalid({nullInput: true});
}
return makeMoment(c);
};
- moment.createFromInputFallback = function (config) {
+ moment.createFromInputFallback = deprecate(
+ "moment construction falls back to js Date. This is " +
+ "discouraged and will be removed in upcoming major " +
+ "release. Please refer to " +
+ "https://github.com/moment/moment/issues/1407 for more info.",
+ function (config) {
config._d = new Date(config._i);
- };
+ });
// creating with utc
moment.utc = function (input, format, lang, strict) {
}
});
- function deprecate(msg, fn) {
- var firstTime = true;
- function printMsg() {
- if (typeof console !== 'undefined' && console.warn) {
- console.warn("Deprecation warning: " + msg);
- }
- }
- return extend(function () {
- if (firstTime) {
- printMsg();
- firstTime = false;
- }
- return fn.apply(this, arguments);
- }, fn);
- }
-
function rawMonthSetter(mom, value) {
var dayOfMonth;
test.done();
},
- "string without format" : function (test) {
- test.expect(2);
- test.ok(moment("Aug 9, 1995").toDate() instanceof Date, "Aug 9, 1995");
- test.ok(moment("Mon, 25 Dec 1995 13:30:00 GMT").toDate() instanceof Date, "Mon, 25 Dec 1995 13:30:00 GMT");
- test.done();
- },
-
"string without format - json" : function (test) {
test.expect(5);
test.equal(moment("Date(1325132654000)").valueOf(), 1325132654000, "Date(1325132654000)");
};
test.ok(moment.isMoment(moment()), 'simple moment object');
- test.ok(moment.isMoment(moment('invalid date')), 'invalid moment object');
+ test.ok(moment.isMoment(moment(null)), 'invalid moment object');
test.ok(moment.isMoment(extend({}, moment())), 'externally cloned moments are moments');
test.ok(moment.isMoment(extend({}, moment.utc())), 'externally cloned utc moments are moments');
test.done();
},
- "string nonsensical" : function (test) {
- test.expect(1);
-
- test.equal(moment('fail').isValid(), false, 'string "fail"');
- test.done();
- },
-
"string nonsensical with format" : function (test) {
test.expect(2);
"empty" : function (test) {
test.equal(moment(null).isValid(), false, 'null');
test.equal(moment('').isValid(), false, 'empty string');
- test.equal(moment(' ').isValid(), false, 'empty when trimmed');
test.equal(moment(null, 'YYYY').isValid(), false, 'format + null');
test.equal(moment('', 'YYYY').isValid(), false, 'format + empty string');