diff --git a/pikaday.js b/pikaday.js index ca3570d6..4ee14081 100644 --- a/pikaday.js +++ b/pikaday.js @@ -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); @@ -812,7 +810,10 @@ */ setMinDate: function(value) { + setToStartOfDay(value); this._o.minDate = value; + this._o.minYear = value.getFullYear(); + this._o.minMonth = value.getMonth(); }, /** diff --git a/tests/methods.js b/tests/methods.js index 65f69a83..e8871f00 100644 --- a/tests/methods.js +++ b/tests/methods.js @@ -23,4 +23,25 @@ describe('Pikaday public method', function () expect(pikaday.toString()).to.eql('25-04-14'); }); }); -}); \ No newline at end of file + + 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); + }); + }); +});