I'm getting Deprecation warning: 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.
But I'm a newbie I cannot figure out how to fix it so the above message disappear.
I think the problem lies in these two lines but I'm not sure.
var nextMonth = moment(moment(year + "-" + month + "-1")).add(1, "months").format("MM");
var nextYear = moment(moment(year + "-" + month + "-1")).add(1, "months").format("YYYY");
I have already checked https://github.com/moment/moment/issues/1407 and Deprecation warning: moment construction falls back to js Date but neither seems to work on my problem.
I would like to know where in this calculation I should tell the format to the moment or at least how to make this calculations in the right format so the warning disappears.
Thanks in advance!
Moment construction falls back to js Date. This is discouraged and will be removed in an upcoming major release. This deprecation warning is thrown when no known format is found for a date passed into the string constructor. To work around this issue, specify a format for the string being passed to moment() .
MomentJs recently announced that the library is now deprecated. This is a big deal for the javascript community who actively downloads moment almost 15 million times a week. With that I began a journey during a Hackathon to replace moment in a core library at my company.
There are several libraries out there that can potentially replace Moment in your app. The creators of Moment recommend looking into Luxon, Day. js, date-fns, js-Joda, or even replacing Moment with native JS.
To get current date with Moment and JavaScript, we use the moment function without any arguments. const datetime = moment(); to call moment to get a moment object with the current date.
Actually I found the problem.
By just adding new Date() to both calculations, it normalized again.
var nextMonth = moment(new Date(year, month - 1, 1)).add(1, "months").format("MM");
var nextYear = moment(new Date(year, month - 1, 1)).add(1, "months").format("YYYY");
I hope it help others!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With