Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong month shown when setting minDate to a later year #93

Open
eduter opened this issue Aug 21, 2013 · 3 comments
Open

wrong month shown when setting minDate to a later year #93

eduter opened this issue Aug 21, 2013 · 3 comments

Comments

@eduter
Copy link

eduter commented Aug 21, 2013

When you set minDate for a date after the currently selected date, the calendar, when shown, should display the month where minDate is. This works if both dates are in the same year, but if the new minDate's year is greater than the selected one, the month shown will be a mix of the selected date's month with the minDate's year.

Example:

selected date: 2013-08-21
minDate: 2014-01-21
month shown: 2014-08

Apparently, modifying 2 if statements from the draw method to be like this solved the problem:

if (this._y < minYear) {
    this._y = minYear;
    this._m = minMonth;
} else if (this._y == minYear && !isNaN(minMonth) && this._m < minMonth) {
   this._m = minMonth;
}
if (this._y > maxYear) {
    this._y = maxYear;
    this._m = maxMonth;
} else if (this._y == maxYear && !isNaN(maxMonth) && this._m > maxMonth) {
    this._m = maxMonth;
}
@leads
Copy link

leads commented Sep 30, 2013

Thanks for this solution @eduter

@cupofjoakim
Copy link

Nice. I just wish stuff like this was incorporated into the library instead of laying on the side like this.

@bjbrewster
Copy link

I'm assuming this happens when you initialize Pikaday with a default selected date before the minDate as looking into the setMinDate function (and setMaxDate as well), they do not update the minMonth, minYear, maxMonth, and maxYear options as these are only set on initialisation which is a separate bug in itself. From what I can tell, this does indeed fix the issue mentioned and will add to my PR that fixes many little issues like this.

bjbrewster pushed a commit to bjbrewster/Pikaday that referenced this issue Mar 28, 2014
The wrong month is sometimes shown when minDate  year > default date's

From the issue's description:
When you set minDate for a date after the currently selected date, the calendar, when shown, should display the month where minDate is. This works if both dates are in the same year, but if the new minDate's year is greater than the selected one, the month shown will be a mix of the selected date's month with the minDate's year.

There is a separate issue in that `setMinDate` and `setMaxDate` do not
update the min/maxMonth and min/maxYear internal options.
graste added a commit to graste/Pikaday that referenced this issue Jan 7, 2015
* bjbrewster/master:
  Fix Date.parse bug when using Datejs
  Fix issue Pikaday#93 wrong month sometimes shown
  Update README description of defaultDate option
  Update README
  Add Ember and Knockout examples
  Add inputFormats option and parseDate method
  Add onClear callback and clearInvalidInput option

Conflicts:
	README.md
	pikaday.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants