From 9c5de29f1befa4f5f43c79d13dd6151b89e3827f Mon Sep 17 00:00:00 2001 From: Bruno Harbulot Date: Mon, 28 Feb 2011 12:18:46 +0000 Subject: [PATCH 1/3] Added timezone selection. --- jquery-ui-timepicker-addon.js | 60 ++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 11 deletions(-) diff --git a/jquery-ui-timepicker-addon.js b/jquery-ui-timepicker-addon.js index 0b11a97..19c1b7b 100644 --- a/jquery-ui-timepicker-addon.js +++ b/jquery-ui-timepicker-addon.js @@ -37,7 +37,8 @@ function Timepicker() { timeText: 'Time', hourText: 'Hour', minuteText: 'Minute', - secondText: 'Second' + secondText: 'Second', + timezoneText: 'Time Zone' }; this._defaults = { // Global defaults for all the datetime picker instances showButtonPanel: true, @@ -45,6 +46,7 @@ function Timepicker() { showHour: true, showMinute: true, showSecond: false, + showTimezone: false, showTime: true, stepHour: 0.05, stepMinute: 0.05, @@ -66,7 +68,11 @@ function Timepicker() { alwaysSetTime: true, separator: ' ', altFieldTimeOnly: true, - showTimepicker: true + showTimepicker: true, + timezoneList: ["-1100", "-1000", "-0900", "-0800", "-0700", "-0600", + "-0500", "-0400", "-0300", "-0200", "-0100", "+0000", + "+0100", "+0200", "+0300", "+0400", "+0500", "+0600", + "+0700", "+0800", "+0900", "+1000", "+1100", "+1200"] }; $.extend(this._defaults, this.regional['']); } @@ -79,9 +85,11 @@ $.extend(Timepicker.prototype, { hour_slider: null, minute_slider: null, second_slider: null, + timezone_select: null, hour: 0, minute: 0, second: 0, + timezone: '+0000', hourMinOriginal: null, minuteMinOriginal: null, secondMinOriginal: null, @@ -92,6 +100,10 @@ $.extend(Timepicker.prototype, { formattedDate: '', formattedTime: '', formattedDateTime: '', + timezoneList: ["-1100", "-1000", "-0900", "-0800", "-0700", "-0600", + "-0500", "-0400", "-0300", "-0200", "-0100", "+0000", + "+0100", "+0200", "+0300", "+0400", "+0500", "+0600", + "+0700", "+0800", "+0900", "+1000", "+1100", "+1200"], /* Override the default settings for all instances of the time picker. @param settings object - the new settings to use as defaults (anonymous object) @@ -112,6 +124,7 @@ $.extend(Timepicker.prototype, { tp_inst.minute = tp_inst._defaults.minute; tp_inst.second = tp_inst._defaults.second; tp_inst.ampm = ''; + tp_inst.timezone = tp_inst._defaults.timezone; tp_inst.$input = $input; @@ -185,6 +198,7 @@ $.extend(Timepicker.prototype, { .replace(/m{1,2}/ig, '(\\d?\\d)') .replace(/s{1,2}/ig, '(\\d?\\d)') .replace(/t{1,2}/ig, '(am|pm|a|p)?') + .replace(/z{1}/ig, '((\\+|-)\\d\\d\\d\\d)?') .replace(/\s/g, '\\s?') + '$', order = this._getFormatPositions(), treg; @@ -197,7 +211,7 @@ $.extend(Timepicker.prototype, { var dp_dateFormat = $.datepicker._get(this.inst, 'dateFormat'); regstr = '.{' + dp_dateFormat.length + ',}' + this._defaults.separator + regstr; } - + treg = timeString.match(new RegExp(regstr, 'i')); if (treg) { @@ -216,6 +230,7 @@ $.extend(Timepicker.prototype, { if (order.m !== -1) this.minute = Number(treg[order.m]); if (order.s !== -1) this.second = Number(treg[order.s]); + if (order.z !== -1) this.timezone = treg[order.z]; return true; @@ -227,8 +242,8 @@ $.extend(Timepicker.prototype, { // figure out position of time elements.. cause js cant do named captures //######################################################################## _getFormatPositions: function() { - var finds = this._defaults.timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|t{1,2})/g), - orders = { h: -1, m: -1, s: -1, t: -1 }; + var finds = this._defaults.timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|t{1,2}|z)/g), + orders = { h: -1, m: -1, s: -1, t: -1, z: -1 }; if (finds) for (var i = 0; i < finds.length; i++) @@ -328,6 +343,11 @@ $.extend(Timepicker.prototype, { ''; } else html += '
'; + + html += '
' + o.timezoneText + '
'; + html += '
'; html += ''; $tp = $(html); @@ -379,6 +399,20 @@ $.extend(Timepicker.prototype, { tp_inst._onTimeChange(); } }); + + + this.timezone_select = $tp.find('#ui_tpicker_timezone_'+ dp_id).append('').find("select"); + $.fn.append.apply(this.timezone_select, + $.map(o.timezoneList, function(val, idx) { + return $("