Skip to content

Commit

Permalink
Fixed !!date issue and can use only minDate or minDateTime as options
Browse files Browse the repository at this point in the history
  • Loading branch information
trentrichardson committed Dec 22, 2010
1 parent 895d27f commit c00fa6d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions jquery-ui-timepicker-addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* jQuery timepicker addon
* By: Trent Richardson [http://trentrichardson.com]
* Version 0.9.2-dev
* Last Modified: 12/17/2010
* Last Modified: 12/22/2010
*
* Copyright 2010 Trent Richardson
* Dual licensed under the MIT and GPL licenses.
Expand Down Expand Up @@ -149,6 +149,17 @@ $.extend(Timepicker.prototype, {
},
timepicker: tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker');
});

// datepicker needs minDate/maxDate, timepicker needs minDateTime/maxDateTime..
if(tp_inst._defaults.minDate !== undefined && tp_inst._defaults.minDate !== null)
tp_inst._defaults.minDateTime = new Date(tp_inst._defaults.minDate.getTime());
if(tp_inst._defaults.minDateTime !== undefined && tp_inst._defaults.minDateTime !== null)
tp_inst._defaults.minDate = new Date(tp_inst._defaults.minDateTime.getTime());
if(tp_inst._defaults.maxDate !== undefined && tp_inst._defaults.maxDate !== null)
tp_inst._defaults.maxDateTime = new Date(tp_inst._defaults.maxDate.getTime());
if(tp_inst._defaults.maxDateTime !== undefined && tp_inst._defaults.maxDateTime !== null)
tp_inst._defaults.maxDate = new Date(tp_inst._defaults.maxDateTime.getTime());

return tp_inst;
},

Expand Down Expand Up @@ -499,7 +510,7 @@ $.extend(Timepicker.prototype, {
this._defaults.minuteMax = maxDateTime.getMinutes();
this._defaults.secondMax = maxDateTime.getSeconds();

if(this.hour > this._defaults.hourMax) this.hour = this._defaults.hourMax;
if(this.hour > this._defaults.hourMax){ this.hour = this._defaults.hourMax; }
if(this.minute > this._defaults.minuteMax) this.minute = this._defaults.minuteMax;
if(this.second > this._defaults.secondMax) this.second = this._defaults.secondMax;
}else{
Expand Down Expand Up @@ -822,7 +833,7 @@ $.datepicker._setTimeDatepicker = function(target, date, withDate) {
$.datepicker._base_setDateDatepicker = $.datepicker._setDateDatepicker;
$.datepicker._setDateDatepicker = function(target, date) {
var inst = this._getInst(target),
tp_date = !!date ? new Date(date.getTime()) : date;
tp_date = (date instanceof Date) ? new Date(date.getTime()) : date;

this._updateDatepicker(inst);
this._base_setDateDatepicker.apply(this, arguments);
Expand Down

0 comments on commit c00fa6d

Please sign in to comment.