DanielYKPan / date-time-picker

Angular Date Time Picker (Responsive Design)
https://daniel-projects.firebaseapp.com/owlng/date-time-picker
MIT License
562 stars 358 forks source link

ERROR in owl-date-time-inline #657

Open tijuhasz opened 4 years ago

tijuhasz commented 4 years ago

I installed "ng-pick-datetime": "^7.0.0" and also tried 6.0.16 in an Angular 8 project. Both give the error described below.

In my view file I use: <owl-date-time-inline [(ngModel)]="date"

where date is a Javascript Date object. The date picker is displayed and it works fine except for the following error.

When selecting a new day in the same month, I get the following error in the console: OwlDateTimeContainerComponent.ngfactory.js? [sm]:1 ERROR TypeError: date.getHours is not a function at NativeDateTimeAdapter.push../node_modules/ng-pick-datetime/date-time/adapter/native-date-time-adapter.class.js.NativeDateTimeAdapter.getHours (native-date-time-adapter.class.js:69) at OwlDateTimeContainerComponent.push../node_modules/ng-pick-datetime/date-time/date-time-picker-container.component.js.OwlDateTimeContainerComponent.updateAndCheckCalendarDate (date-time-picker-container.component.js:325) at OwlDateTimeContainerComponent.push../node_modules/ng-pick-datetime/date-time/date-time-picker-container.component.js.OwlDateTimeContainerComponent.dateSelectedInSingleMode (date-time-picker-container.component.js:287) at OwlDateTimeContainerComponent.push../node_modules/ng-pick-datetime/date-time/date-time-picker-container.component.js.OwlDateTimeContainerComponent.dateSelected (date-time-picker-container.component.js:186) at Object.eval [as handleEvent] (OwlDateTimeContainerComponent.html:1) at handleEvent (core.js:43993) at callWithDebugContext (core.js:45632) at Object.debugHandleEvent [as handleEvent] (core.js:45247) at dispatchEvent (core.js:29804) at core.js:31837

If I switch to a different month and then switch back without changing the month, I can select a new day without the error.

Please help!

tijuhasz commented 4 years ago

The issue is in file date-time-picker-container.component.js in function updateAndCheckCalendarDate()

because this.pickerMoment is not initialized when the function is initially called.

I added this.pickerMoment = this.picker.startAt || this.dateTimeAdapter.now(); to the start of this function and the bug is patched.