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

convertDateToMinOrMaxDate #581

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -96,6 +96,7 @@ Pikaday has many useful options:
* `yearSuffix` additional text to append to the year in the title
* `showMonthAfterYear` render the month after year in the title (default `false`)
* `showDaysInNextAndPreviousMonths` render days of the calendar grid that fall in the next or previous months to the current month instead of rendering an empty table cell (default: false)
* `convertDateToMinOrMaxDate` If minDate or maxDate is supplied then by default `setDate` function will convert date to minDate, if passed date is less than minDate, or convert date to maxDate, if passed date is greater than maxDate. Set this to false if you dont want this behaviour. (default: true)
* `numberOfMonths` number of visible calendars
* `mainCalendar` when `numberOfMonths` is used, this will help you to choose where the main calendar will be (default `left`, can be set to `right`). Only used for the first display or when a selected date is not already visible
* `theme` define a classname that can be used as a hook for styling different themes, see [theme example][] (default `null`)
Expand Down
18 changes: 12 additions & 6 deletions pikaday.js
Expand Up @@ -236,6 +236,10 @@
// Render days of the calendar grid that fall in the next or previous month
showDaysInNextAndPreviousMonths: false,

// If minDate and maxDate are supplied then convert date to minDate, if passed date is less than minDate
// or convert date to maxDate, if passed date is greater than max Date.
convertDateToMinOrMaxDate: true,

// how many months are visible
numberOfMonths: 1,

Expand Down Expand Up @@ -753,13 +757,15 @@
return;
}

var min = this._o.minDate,
max = this._o.maxDate;
if (this._o.convertDateToMinOrMaxDate) {
var min = this._o.minDate,
max = this._o.maxDate;

if (isDate(min) && date < min) {
date = min;
} else if (isDate(max) && date > max) {
date = max;
if (isDate(min) && date < min) {
date = min;
} else if (isDate(max) && date > max) {
date = max;
}
}

this._d = new Date(date.getTime());
Expand Down