8000 Ensure createFromInputFallback is called in all cases by ichernev · Pull Request #1604 · moment/moment · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Ensure createFromInputFallback is called in all cases #1604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 28 additions & 20 deletions moment.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,23 @@
};
}

function deprecate(msg, fn) {
var firstTime = true;
function printMsg() {
if (moment.suppressDeprecationWarnings === false &&
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);
Expand Down Expand Up @@ -1415,7 +1432,7 @@
makeDateFromStringAndFormat(config);
}
else {
config._d = new Date(string);
config._d = moment.createFromInputFallback(string);
}
}

Expand Down Expand Up @@ -1567,7 +1584,7 @@
var input = config._i,
format = config._f;

if (input === null) {
if (input === null || (format === undefined && input === '')) {
return moment.invalid({nullInput: true});
}

Expand Down Expand Up @@ -1613,9 +1630,16 @@
return makeMoment(c);
};

moment.createFromInputFallback = function (config) {
moment.suppressDeprecationWarnings = false;

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) {
Expand Down Expand Up @@ -2192,22 +2216,6 @@
}
});

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;

Expand Down
7 changes: 0 additions & 7 deletions test/moment/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,6 @@ exports.create = {
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);< 10000 /span>
test.equal(moment("Date(1325132654000)").valueOf(), 1325132654000, "Date(1325132654000)");
Expand Down
2 changes: 1 addition & 1 deletion test/moment/is_moment.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ exports.isMoment = {
};

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');

Expand Down
8 changes: 0 additions & 8 deletions test/moment/is_valid.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,6 @@ exports.isValid = {
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);

Expand Down Expand Up @@ -239,7 +232,6 @@ exports.isValid = {
"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');
Expand Down
0