alenaksu / mdPickers

Material Design date/time pickers for Angular Material
MIT License
293 stars 216 forks source link

max and min date also compares by time #181

Open AnirudhaGohokar opened 7 years ago

AnirudhaGohokar commented 7 years ago

Hi,

When using mdp-max-date and mpd-min-date, the comparison is being done with time as well. So, consider this

max date--> Wed Jan 31 2018 00:00:00 GMT+0530 (India Standard Time)
current date--> Wed Jan 31 2018 12:43:47 GMT+0530 (India Standard Time)

will evaluate to false even though the dates match becuase current date > max date

A simple change of doing comparison based on date only in isDayEnabled function should fix the issue.

AnirudhaGohokar commented 7 years ago

For now I have fixed this issue by stripping out the time in isDayEnabled function and it seems to be working good.

this.isDayEnabled = function (day) {
                var min_date = this.minDate ? moment(this.minDate).startOf('day').toDate() : false;
                var max_date = this.maxDate ? moment(this.maxDate).startOf('day').toDate() : false;
                var current_date = moment(day).startOf('day').toDate();
                var isEnabled = (!min_date || min_date <= current_date) &&
                        (!max_date || max_date >= current_date) &&
                        (!self.dateFilter || !self.dateFilter(current_date));
                return isEnabled;
            };