Skip to content

Commit

Permalink
Merge pull request Pikaday#262 from stuart-bennett/master
Browse files Browse the repository at this point in the history
Make setMinDate() behaviour consistent with the "minDate" option in constructor
  • Loading branch information
rikkert committed Feb 18, 2015
2 parents 493024d + c0ed319 commit f2c8d56
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
7 changes: 4 additions & 3 deletions pikaday.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,9 +621,7 @@
opts.maxDate = opts.minDate = false;
}
if (opts.minDate) {
setToStartOfDay(opts.minDate);
opts.minYear = opts.minDate.getFullYear();
opts.minMonth = opts.minDate.getMonth();
this.setMinDate(opts.minDate)
}
if (opts.maxDate) {
setToStartOfDay(opts.maxDate);
Expand Down Expand Up @@ -812,7 +810,10 @@
*/
setMinDate: function(value)
{
setToStartOfDay(value);
this._o.minDate = value;
this._o.minYear = value.getFullYear();
this._o.minMonth = value.getMonth();
},

/**
Expand Down
23 changes: 22 additions & 1 deletion tests/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,25 @@ describe('Pikaday public method', function ()
expect(pikaday.toString()).to.eql('25-04-14');
});
});
});

describe('When specifying minDate option in Constructor', function () {
it('Should remove the time portion (flattening to midnight)', function () {
var date = new Date(2015, 1, 17, 22, 10, 5),
expected = new Date(2015, 1, 17, 0, 0, 0),
pikaday = new Pikaday({ minDate: date });

expect(pikaday._o.minDate).to.eql(expected);
});
});

describe('#setMinDate()', function () {
it('should flatten date to midnight ignoring time portion (consistent with minDate option in ctor)', function () {
var date = new Date(2015, 1, 17, 22, 10, 5),
expected = new Date(2015, 1, 17, 0, 0, 0),
pikaday = new Pikaday();

pikaday.setMinDate(date);
expect(pikaday._o.minDate).to.eql(expected);
});
});
});

0 comments on commit f2c8d56

Please sign in to comment.