summaryrefslogtreecommitdiffstats
path: root/jquery-ui-timepicker-addon.js
diff options
context:
space:
mode:
authorTrent Richardson <trentdrichardson@gmail.com>2012-03-22 05:16:20 -0700
committerTrent Richardson <trentdrichardson@gmail.com>2012-03-22 05:16:20 -0700
commit480135aa32bdeb2a42a2a7bea44e3e73531e8103 (patch)
treeff6bc97735cad6708e18ff8e9373cd084bd68eca /jquery-ui-timepicker-addon.js
parentea30cab7c7ac31338a18060ad52a0d74b82cd815 (diff)
parent313e55d76a668a8faa6741fad97e0a996b553069 (diff)
downloadjQuery-Timepicker-Addon-480135aa32bdeb2a42a2a7bea44e3e73531e8103.zip
jQuery-Timepicker-Addon-480135aa32bdeb2a42a2a7bea44e3e73531e8103.tar.gz
jQuery-Timepicker-Addon-480135aa32bdeb2a42a2a7bea44e3e73531e8103.tar.bz2
Merge pull request #338 from apepper/autoselect_current_timezone
Pick the current timezone of the browser by default.
Diffstat (limited to 'jquery-ui-timepicker-addon.js')
-rw-r--r--jquery-ui-timepicker-addon.js38
1 files changed, 25 insertions, 13 deletions
diff --git a/jquery-ui-timepicker-addon.js b/jquery-ui-timepicker-addon.js
index f14c02d..76c236c 100644
--- a/jquery-ui-timepicker-addon.js
+++ b/jquery-ui-timepicker-addon.js
@@ -110,7 +110,6 @@ $.extend(Timepicker.prototype, {
minute: 0,
second: 0,
millisec: 0,
- timezone: '+0000',
hourMinOriginal: null,
minuteMinOriginal: null,
secondMinOriginal: null,
@@ -444,7 +443,11 @@ $.extend(Timepicker.prototype, {
.text(typeof val == "object" ? val.label : val);
})
);
- this.timezone_select.val((typeof this.timezone != "undefined" && this.timezone != null && this.timezone != "") ? this.timezone : o.timezone);
+ if (typeof this.timezone != "undefined" && this.timezone != null && this.timezone != "") {
+ this.timezone_select.val(this.timezone);
+ } else {
+ selectLocalTimeZone(tp_inst);
+ }
this.timezone_select.change(function() {
tp_inst._onTimeChange();
});
@@ -1125,18 +1128,9 @@ $.datepicker._gotoToday = function(id) {
var inst = this._getInst($(id)[0]),
$dp = inst.dpDiv;
this._base_gotoToday(id);
- var now = new Date();
var tp_inst = this._get(inst, 'timepicker');
- if (tp_inst && tp_inst._defaults.showTimezone && tp_inst.timezone_select) {
- var tzoffset = now.getTimezoneOffset(); // If +0100, returns -60
- var tzsign = tzoffset > 0 ? '-' : '+';
- tzoffset = Math.abs(tzoffset);
- var tzmin = tzoffset % 60;
- tzoffset = tzsign + ('0' + (tzoffset - tzmin) / 60).slice(-2) + ('0' + tzmin).slice(-2);
- if (tp_inst._defaults.timezoneIso8601)
- tzoffset = tzoffset.substring(0, 3) + ':' + tzoffset.substring(3);
- tp_inst.timezone_select.val(tzoffset);
- }
+ selectLocalTimeZone(tp_inst);
+ var now = new Date();
this._setTime(inst, now);
$( '.ui-datepicker-today', $dp).click();
};
@@ -1403,6 +1397,24 @@ var parseDateTimeInternal = function(dateFormat, timeFormat, dateTimeString, dat
return {date: date};
}
+//#######################################################################################
+// Internal function to set timezone_select to the local timezone
+//#######################################################################################
+var selectLocalTimeZone = function(tp_inst)
+{
+ if (tp_inst && tp_inst._defaults.showTimezone && tp_inst.timezone_select) {
+ var now = new Date();
+ var tzoffset = now.getTimezoneOffset(); // If +0100, returns -60
+ var tzsign = tzoffset > 0 ? '-' : '+';
+ tzoffset = Math.abs(tzoffset);
+ var tzmin = tzoffset % 60;
+ tzoffset = tzsign + ('0' + (tzoffset - tzmin) / 60).slice(-2) + ('0' + tzmin).slice(-2);
+ if (tp_inst._defaults.timezoneIso8601)
+ tzoffset = tzoffset.substring(0, 3) + ':' + tzoffset.substring(3);
+ tp_inst.timezone_select.val(tzoffset);
+ }
+}
+
$.timepicker = new Timepicker(); // singleton instance
$.timepicker.version = "1.0.1";