Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Date() support added for setTime, getTimeAsDate added #53

Merged
merged 1 commit into from

3 participants

AAverin Francois Gelinas Check your git settings!
AAverin

setTime can now have Date() object as an argument
getTimeAsDate method was added to retrieve time as date
inst.minuts renamed to inst.minutes

and btw, why not use underlying Date object to store all of the time settings?

Anton Averin setTime now can have Date() object as an argument
getTimeAsDate method was added to retrieve time as date
inst.minuts renamed to inst.minutes
021838b
Francois Gelinas
Owner

Thanks for the pull request, I'll check it later.
For the Date object question, at first I did not think of it and if I was to write the plugin again, I would use it.
But using the Date object has some limitations too like when only minutes or hours are selected. Also the timepicker is not limited to valid minutes / hours so one can set options to enter minutes ranging from 1 to 100.

Francois Gelinas fgelinas merged commit 5fbb73c into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 21, 2012
  1. setTime now can have Date() object as an argument

    Anton Averin authored
    getTimeAsDate method was added to retrieve time as date
    inst.minuts renamed to inst.minutes
This page is out of date. Refresh to see the latest.
Showing with 23 additions and 5 deletions.
  1. +23 −5 jquery.ui.timepicker.js
28 jquery.ui.timepicker.js
View
@@ -1100,11 +1100,16 @@
_setTime: function(inst, time, noChange) {
var origHours = inst.hours;
var origMinutes = inst.minutes;
- var time = this.parseTime(inst, time);
- inst.hours = time.hours;
- inst.minutes = time.minutes;
+ if (time instanceof Date) {
+ inst.hours = time.getHours();
+ inst.minutes = time.getMinutes();
+ } else {
+ var time = this.parseTime(inst, time);
+ inst.hours = time.hours;
+ inst.minutes = time.minutes;
+ }
- if ((origHours != inst.hours || origMinutes != inst.minuts) && !noChange) {
+ if ((origHours != inst.hours || origMinutes != inst.minutes) && !noChange) {
inst.input.trigger('change');
}
this._updateTimepicker(inst);
@@ -1338,6 +1343,19 @@
}
},
+ _getTimeAsDateTimepicker: function(input) {
+ var inst = this._getInst(input);
+ if (inst.hours == -1 && inst.minutes == -1) {
+ return '';
+ }
+
+ // default to 0 AM if hours is not valid
+ if ((inst.hours < inst.hours.starts) || (inst.hours > inst.hours.ends )) { inst.hours = 0; }
+ // default to 0 minutes if minute is not valid
+ if ((inst.minutes < inst.minutes.starts) || (inst.minutes > inst.minutes.ends)) { inst.minutes = 0; }
+
+ return new Date(0, 0, 0, inst.hours, inst.minutes, 0);
+ },
/* This might look unused but it's called by the $.fn.timepicker function with param getTime */
/* added v 0.2.3 - gitHub issue #5 - Thanks edanuff */
_getTimeTimepicker : function(input) {
@@ -1375,7 +1393,7 @@
var otherArgs = Array.prototype.slice.call(arguments, 1);
- if (typeof options == 'string' && (options == 'getTime' || options == 'getHour' || options == 'getMinute' ))
+ if (typeof options == 'string' && (options == 'getTime' || options == 'getTimeAsDate' || options == 'getHour' || options == 'getMinute' ))
return $.timepicker['_' + options + 'Timepicker'].
apply($.timepicker, [this[0]].concat(otherArgs));
if (options == 'option' && arguments.length == 2 && typeof arguments[1] == 'string')
Something went wrong with that request. Please try again.