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
Parse value without fallback #2469
Comments
Just to clarify, you're asking for a way to disable to fall-back rather than show the warning - without using strict mode, right? |
Yes I want to automatically parse all the things that I want to preemptively opt-in to the behaviour of a future version of I'm not sure exactly what you mean by strict mode. Do you mean when passing the exact format like |
Strict mode is enabled by passing Since the formats supported directly by |
Yes that would be great. Thanks. |
@SystemParadox yes, what you want IS supported. You just override moment.createFromInputFallback = function (config) {
config._d = new Date(NaN);
} I agree it is not trivial, but it is possible ;-) |
That's helpful, but changes the setting globally. What if I want to progressively migrate a codebase one call at a time? Why can we not just add support for |
Reopening, while there is the workaround, having this in the public API would help a variety of use cases. Consider also #2535, asking for validation around just the build-in formats. |
What is needed is the moment.JS_DATE constant, that means just pass the input to |
@SystemParadox in case it's helpful, I had a similar issue to yours and I wound up creating wrapper functions like this: function disableNativeDateFallback(config) {
config._d = new Date(parseFloat('NaN')); // an invalid date
}
function makeMomentWrapper(momentFn) {
return function() {
var prevFallback = moment.createFromInputFallback;
moment.createFromInputFallback = disableNativeDateFallback;
var result = momentFn.apply(null, arguments);
moment.createFromInputFallback = prevFallback;
return result;
}
};
var momentStrict = makeMomentWrapper(moment);
momentStrict.utc = makeMomentWrapper(moment.utc); They work by replacing |
Passing an arbitrary value to
moment(value)
produces a deprecation warning as per #1407.It would be really nice if there was some way to use this parsing but without falling back to the Date constructor. The only way I have found so far is fairly clumsy:
And even then this still doesn't parse ASP.net
/Date(1198908717056)/
strings.The simplest option would be to allow the strict option in two-argument form:
moment(value, true)
.Thanks.
The text was updated successfully, but these errors were encountered: