ng2-ui / datetime-picker

Angular2 DateTime Picker
https://ng2-ui.github.io/#/datetime-picker
MIT License
121 stars 62 forks source link

Moment deprecation warning #110

Closed afnpires closed 7 years ago

afnpires commented 7 years ago

Warning being shown in the console.

moment.min.js:17 Deprecation warning: moment construction falls back to js Date. This is discouraged and will be removed in upcoming major release. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
Arguments: [object Object]
Error
    at Function.createFromInputFallback (http://localhost:51273/app/moment.min.js:17:482) [angular]
    at eb (http://localhost:51273/app/moment.min.js:129:129) [angular]
    at pb (http://localhost:51273/app/moment.min.js:169:413) [angular]
    at ob (http://localhost:51273/app/moment.min.js:169:274) [angular]
    at nb (http://localhost:51273/app/moment.min.js:167:503) [angular]
    at qb (http://localhost:51273/app/moment.min.js:174:164) [angular]
    at rb (http://localhost:51273/app/moment.min.js:174:198) [angular]
    at a (http://localhost:51273/app/moment.min.js:6:202) [angular]
    at Function.Ng2Datetime.parseDate (http://localhost:51273/app/app.bundle.js:15141:24) [angular]
    at Ng2DatetimePickerDirective.getDate (http://localhost:51273/app/app.bundle.js:44742:47) [angular]
    at Ng2DatetimePickerDirective.setInputElDateValue (http://localhost:51273/app/app.bundle.js:44652:41) [angular]
    at Ng2DatetimePickerDirective.valueChanged (http://localhost:51273/app/app.bundle.js:44526:19) [angular]
    at http://localhost:51273/app/app.bundle.js:44630:19 [angular]

In this code:

Ng2Datetime.parseDate = function (dateStr, dateFormat) {
        if (typeof moment === 'undefined') {
            dateStr = Ng2Datetime.removeTimezone(dateStr);
            dateStr = dateStr + Ng2Datetime.addDSTOffset(dateStr);
            return Ng2Datetime.parseFromDefaultFormat(dateStr);
        }
        else if (dateFormat) {
            var date = moment(dateStr, dateFormat).toDate();
            if (isNaN(date.getTime())) {
                date = moment(dateStr).toDate(); //parse as ISO format
            }
            return date;
        }
    };

The moment.js version is 2.14.1.

allenhwkim commented 7 years ago

Thanks for feedback. I have seen and investigated, but no luck yet.

rvdhooft commented 7 years ago

I see this warning when dateStr doesn't match the given dateFormat. Giving moment a default format when parsing the string should remove the error, ie try changing the line date = moment(dateStr).toDate(); //parse as ISO format to date = moment(dateStr, moment.ISO_8601).toDate(); //parse as ISO format

allenhwkim commented 7 years ago

It seems fixed with the recent release, 0.13.0, please verify the change

MateEke commented 7 years ago

0.12.9 is working fine, there is no deprecation warning.