bleenco / ng2-datepicker

Angular2 Datepicker Component
http://ng2-datepicker.jankuri.com
MIT License
310 stars 236 forks source link

No initial date when using Unix Timestamp model-format #16

Open MoreThanCarbon opened 8 years ago

MoreThanCarbon commented 8 years ago

Since the initial date value is a timestamp of 'new Date()' the datepicker selected date does not match any date on the calendar. I was able to get around this by changing:

    private initValue(): void {
        setTimeout(() => {
            if (!this.initDate) {
                this.setValue(moment().format(this.modelFormat || 'YYYY-MM-DD'));
            } else {
                this.setValue(moment(this.initDate, this.modelFormat || 'YYYY-MM-DD'));
             }
        });
    }

to

    private initValue(): void {
        setTimeout(() => {
            if (!this.initDate) {
                this.setValue(moment().startOf('day').format(this.modelFormat || 'YYYY-MM-DD'));
            } else {
                this.setValue(moment(this.initDate, this.modelFormat || 'YYYY-MM-DD'));
             }
        });
    }

on the ng2-datepicker/src/components/ng2-datepicker.ts page.

jkuri commented 8 years ago

Hey, can you post a PR for this please?