Merge timezone additions

This commit is contained in:
Trent Richardson 2011-03-02 11:28:00 -05:00
commit b23b6076fb
2 changed files with 91 additions and 11 deletions

42
example-timezone.html Normal file
View file

@ -0,0 +1,42 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js">/**/</script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js">/**/</script>
<script src="jquery-ui-timepicker-addon.js">/**/</script>
<link rel="stylesheet" type="text/css" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/ui-lightness/jquery-ui.css" />
<style media="screen" type="text/css">
body{ font: Arial, Helvetica, sans-serif; }
#ui-datepicker-div{ font-size: 90%; }
/* css for timepicker */
.ui-timepicker-div .ui-widget-header{ margin-bottom: 8px; }
.ui-timepicker-div dl{ text-align: left; }
.ui-timepicker-div dl dt{ height: 25px; }
.ui-timepicker-div dl dd{ margin: -25px 0 10px 65px; }
.ui-timepicker-div td { font-size: 90%; }
input { width: 200px; }
</style>
<script type="text/javascript">
$(document).ready(function(){
$(".timepicktest0").datetimepicker({ dateFormat: $.datepicker.RFC_2822, timeFormat: 'hh:mm' });
$(".timepicktest1").datetimepicker({ dateFormat: $.datepicker.RFC_2822, timeFormat: 'hh:mm z', showTimezone: true, timezone: "+0100" });
$(".timepicktest2").datetimepicker({ dateFormat: $.datepicker.RFC_2822, timeFormat: 'hh:mm z', showTimezone: true,
timezoneList: [{"value": "+0000", "label": "British Winter Time"}, {"value": "+0100", "label": "British Summer Time"}] });
});
</script>
</head>
<body>
<form action="" method="">
<input type="text" class="timepicktest0" /><br />
<input type="text" class="timepicktest1" /><br />
<input type="text" class="timepicktest1" value="Mon, 28 Feb 2011 10:58"/><br />
<input type="text" class="timepicktest1" value="Mon, 28 Feb 2011 10:58 +0000"/><br />
<input type="text" class="timepicktest2" value="Mon, 28 Feb 2011 10:58 +0000"/><br />
<input type="text" class="timepicktest2" value="Mon, 28 Feb 2011 10:58 +0100"/><br />
</form>
</body>
</html>

View file

@ -37,7 +37,8 @@ function Timepicker() {
timeText: 'Time', timeText: 'Time',
hourText: 'Hour', hourText: 'Hour',
minuteText: 'Minute', minuteText: 'Minute',
secondText: 'Second' secondText: 'Second',
timezoneText: 'Time Zone'
}; };
this._defaults = { // Global defaults for all the datetime picker instances this._defaults = { // Global defaults for all the datetime picker instances
showButtonPanel: true, showButtonPanel: true,
@ -45,6 +46,7 @@ function Timepicker() {
showHour: true, showHour: true,
showMinute: true, showMinute: true,
showSecond: false, showSecond: false,
showTimezone: false,
showTime: true, showTime: true,
stepHour: 0.05, stepHour: 0.05,
stepMinute: 0.05, stepMinute: 0.05,
@ -52,6 +54,7 @@ function Timepicker() {
hour: 0, hour: 0,
minute: 0, minute: 0,
second: 0, second: 0,
timezone: '+0000',
hourMin: 0, hourMin: 0,
minuteMin: 0, minuteMin: 0,
secondMin: 0, secondMin: 0,
@ -66,7 +69,11 @@ function Timepicker() {
alwaysSetTime: true, alwaysSetTime: true,
separator: ' ', separator: ' ',
altFieldTimeOnly: true, 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['']); $.extend(this._defaults, this.regional['']);
} }
@ -79,9 +86,11 @@ $.extend(Timepicker.prototype, {
hour_slider: null, hour_slider: null,
minute_slider: null, minute_slider: null,
second_slider: null, second_slider: null,
timezone_select: null,
hour: 0, hour: 0,
minute: 0, minute: 0,
second: 0, second: 0,
timezone: '+0000',
hourMinOriginal: null, hourMinOriginal: null,
minuteMinOriginal: null, minuteMinOriginal: null,
secondMinOriginal: null, secondMinOriginal: null,
@ -92,6 +101,10 @@ $.extend(Timepicker.prototype, {
formattedDate: '', formattedDate: '',
formattedTime: '', formattedTime: '',
formattedDateTime: '', 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. /* Override the default settings for all instances of the time picker.
@param settings object - the new settings to use as defaults (anonymous object) @param settings object - the new settings to use as defaults (anonymous object)
@ -184,6 +197,7 @@ $.extend(Timepicker.prototype, {
.replace(/m{1,2}/ig, '(\\d?\\d)') .replace(/m{1,2}/ig, '(\\d?\\d)')
.replace(/s{1,2}/ig, '(\\d?\\d)') .replace(/s{1,2}/ig, '(\\d?\\d)')
.replace(/t{1,2}/ig, '(am|pm|a|p)?') .replace(/t{1,2}/ig, '(am|pm|a|p)?')
.replace(/z{1}/ig, '((\\+|-)\\d\\d\\d\\d)?')
.replace(/\s/g, '\\s?') + '$', .replace(/\s/g, '\\s?') + '$',
order = this._getFormatPositions(), order = this._getFormatPositions(),
treg; treg;
@ -215,6 +229,7 @@ $.extend(Timepicker.prototype, {
if (order.m !== -1) this.minute = Number(treg[order.m]); if (order.m !== -1) this.minute = Number(treg[order.m]);
if (order.s !== -1) this.second = Number(treg[order.s]); if (order.s !== -1) this.second = Number(treg[order.s]);
if (order.z !== -1) this.timezone = treg[order.z];
return true; return true;
@ -226,8 +241,8 @@ $.extend(Timepicker.prototype, {
// figure out position of time elements.. cause js cant do named captures // figure out position of time elements.. cause js cant do named captures
//######################################################################## //########################################################################
_getFormatPositions: function() { _getFormatPositions: function() {
var finds = this._defaults.timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|t{1,2})/g), 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 }; orders = { h: -1, m: -1, s: -1, t: -1, z: -1 };
if (finds) if (finds)
for (var i = 0; i < finds.length; i++) for (var i = 0; i < finds.length; i++)
@ -328,6 +343,11 @@ $.extend(Timepicker.prototype, {
} else html += '<dd class="ui_tpicker_second" id="ui_tpicker_second_' + dp_id + '"' + } else html += '<dd class="ui_tpicker_second" id="ui_tpicker_second_' + dp_id + '"' +
((o.showSecond) ? '' : noDisplay) + '></dd>'; ((o.showSecond) ? '' : noDisplay) + '></dd>';
html += '<dt class="ui_tpicker_timezone_label" id="ui_tpicker_timezone_label_' + dp_id + '"' +
((o.showTimezone) ? '' : noDisplay) + '>' + o.timezoneText + '</dt>';
html += '<dd class="ui_tpicker_timezone" id="ui_tpicker_timezone_' + dp_id + '"' +
((o.showTimezone) ? '' : noDisplay) + '></dd>';
html += '</dl></div>'; html += '</dl></div>';
$tp = $(html); $tp = $(html);
@ -379,6 +399,20 @@ $.extend(Timepicker.prototype, {
} }
}); });
this.timezone_select = $tp.find('#ui_tpicker_timezone_'+ dp_id).append('<select></select>').find("select");
$.fn.append.apply(this.timezone_select,
$.map(o.timezoneList, function(val, idx) {
return $("<option />")
.val(typeof val == "object" ? val.value : val)
.text(typeof val == "object" ? val.label : val);
})
);
this.timezone_select.val((typeof this.timezone != "undefined" && this.timezone != null && this.timezone != "") ? this.timezone : o.timezone);
this.timezone_select.change(function() {
tp_inst._onTimeChange();
});
// Add grid functionality // Add grid functionality
if (o.showHour && o.hourGrid > 0) { if (o.showHour && o.hourGrid > 0) {
size = 100 * hourGridSize * o.hourGrid / (hourMax - o.hourMin); size = 100 * hourGridSize * o.hourGrid / (hourMax - o.hourMin);
@ -546,7 +580,8 @@ $.extend(Timepicker.prototype, {
_onTimeChange: function() { _onTimeChange: function() {
var hour = (this.hour_slider) ? this.hour_slider.slider('value') : false, var hour = (this.hour_slider) ? this.hour_slider.slider('value') : false,
minute = (this.minute_slider) ? this.minute_slider.slider('value') : false, minute = (this.minute_slider) ? this.minute_slider.slider('value') : false,
second = (this.second_slider) ? this.second_slider.slider('value') : false; second = (this.second_slider) ? this.second_slider.slider('value') : false,
timezone = (this.timezone_select) ? this.timezone_select.val() : false
if (hour !== false) hour = parseInt(hour,10); if (hour !== false) hour = parseInt(hour,10);
if (minute !== false) minute = parseInt(minute,10); if (minute !== false) minute = parseInt(minute,10);
@ -556,13 +591,14 @@ $.extend(Timepicker.prototype, {
// If the update was done in the input field, the input field should not be updated. // If the update was done in the input field, the input field should not be updated.
// If the update was done using the sliders, update the input field. // If the update was done using the sliders, update the input field.
var hasChanged = (hour != this.hour || minute != this.minute || second != this.second || (this.ampm.length > 0 && this.ampm != ampm)); var hasChanged = (hour != this.hour || minute != this.minute || second != this.second || (this.ampm.length > 0 && this.ampm != ampm) || timezone != this.timezone);
if (hasChanged) { if (hasChanged) {
if (hour !== false)this.hour = hour; if (hour !== false)this.hour = hour;
if (minute !== false) this.minute = minute; if (minute !== false) this.minute = minute;
if (second !== false) this.second = second; if (second !== false) this.second = second;
if (timezone !== false) this.timezone = timezone;
} }
if (this._defaults.ampm) this.ampm = ampm; if (this._defaults.ampm) this.ampm = ampm;
@ -589,7 +625,7 @@ $.extend(Timepicker.prototype, {
//######################################################################## //########################################################################
_formatTime: function(time, format, ampm) { _formatTime: function(time, format, ampm) {
if (ampm == undefined) ampm = this._defaults.ampm; if (ampm == undefined) ampm = this._defaults.ampm;
time = time || { hour: this.hour, minute: this.minute, second: this.second, ampm: this.ampm }; time = time || { hour: this.hour, minute: this.minute, second: this.second, ampm: this.ampm, timezone: this.timezone };
var tmptime = format || this._defaults.timeFormat.toString(); var tmptime = format || this._defaults.timeFormat.toString();
if (ampm) { if (ampm) {
@ -605,7 +641,8 @@ $.extend(Timepicker.prototype, {
.replace(/TT/g, time.ampm.toUpperCase()) .replace(/TT/g, time.ampm.toUpperCase())
.replace(/tt/g, time.ampm.toLowerCase()) .replace(/tt/g, time.ampm.toLowerCase())
.replace(/T/g, time.ampm.charAt(0).toUpperCase()) .replace(/T/g, time.ampm.charAt(0).toUpperCase())
.replace(/t/g, time.ampm.charAt(0).toLowerCase()); .replace(/t/g, time.ampm.charAt(0).toLowerCase())
.replace(/z/g, time.timezone);
} else { } else {
tmptime = tmptime.toString() tmptime = tmptime.toString()
.replace(/hh/g, ((time.hour < 10) ? '0' : '') + time.hour) .replace(/hh/g, ((time.hour < 10) ? '0' : '') + time.hour)
@ -613,7 +650,8 @@ $.extend(Timepicker.prototype, {
.replace(/mm/g, ((time.minute < 10) ? '0' : '') + time.minute) .replace(/mm/g, ((time.minute < 10) ? '0' : '') + time.minute)
.replace(/m/g, time.minute) .replace(/m/g, time.minute)
.replace(/ss/g, ((time.second < 10) ? '0' : '') + time.second) .replace(/ss/g, ((time.second < 10) ? '0' : '') + time.second)
.replace(/s/g, time.second); .replace(/s/g, time.second)
.replace(/z/g, time.timezone);
tmptime = $.trim(tmptime.replace(/t/gi, '')); tmptime = $.trim(tmptime.replace(/t/gi, ''));
} }