|
239 | 239 | tp_inst.control = tp_inst._defaults.controlType; |
240 | 240 | } |
241 | 241 |
|
242 | | - if (tp_inst._defaults.timezoneList === null) { |
243 | | - var timezoneList = ['-1200', '-1100', '-1000', '-0930', '-0900', '-0800', '-0700', '-0600', '-0500', '-0430', '-0400', '-0330', '-0300', '-0200', '-0100', '+0000', |
244 | | - '+0100', '+0200', '+0300', '+0330', '+0400', '+0430', '+0500', '+0530', '+0545', '+0600', '+0630', '+0700', '+0800', '+0845', '+0900', '+0930', |
245 | | - '+1000', '+1030', '+1100', '+1130', '+1200', '+1245', '+1300', '+1400']; |
246 | | - |
247 | | - if (tp_inst.support.iso8601) { |
248 | | - timezoneList = $.map(timezoneList, function(val) { |
249 | | - return val == '+0000' ? 'Z' : (val.substring(0, 3) + ':' + val.substring(3)); |
250 | | - }); |
| 242 | + // prep the timezone options |
| 243 | + var timezoneList = [-720,-660,-600,-570,-540,-480,-420,-360,-300,-270,-240,-210,-180,-120,-60, |
| 244 | + 0,60,120,180,210,240,270,300,330,345,360,390,420,480,525,540,570,600,630,660,690,720,765,780,840]; |
| 245 | + if (tp_inst._defaults.timezoneList !== null) { |
| 246 | + timezoneList = tp_inst._defaults.timezoneList; |
| 247 | + } |
| 248 | + var tzl=timezoneList.length,tzi=0,tzv=null; |
| 249 | + if (tzl > 0 && typeof timezoneList[0] !== 'object') { |
| 250 | + for(; tzi<tzl; tzi++){ |
| 251 | + tzv = timezoneList[tzi]; |
| 252 | + timezoneList[tzi] = { value: tzv, label: $.timepicker.timezoneOffsetString(tzv, tp_inst.support.iso8601) }; |
251 | 253 | } |
252 | | - tp_inst._defaults.timezoneList = timezoneList; |
253 | 254 | } |
| 255 | + tp_inst._defaults.timezoneList = timezoneList; |
254 | 256 |
|
255 | | - tp_inst.timezone = tp_inst._defaults.timezone !== null? tp_inst._defaults.timezone : |
256 | | - $.timepicker.timezoneOffsetString((new Date()).getTimezoneOffset(), tp_inst.support.iso8601); |
| 257 | + // set the default units |
| 258 | + tp_inst.timezone = tp_inst._defaults.timezone !== null? $.timepicker.timezoneOffsetNumber(tp_inst._defaults.timezone) : |
| 259 | + ((new Date()).getTimezoneOffset()*-1); |
257 | 260 | tp_inst.hour = tp_inst._defaults.hour < tp_inst._defaults.hourMin? tp_inst._defaults.hourMin : |
258 | 261 | tp_inst._defaults.hour > tp_inst._defaults.hourMax? tp_inst._defaults.hourMax : tp_inst._defaults.hour; |
259 | 262 | tp_inst.minute = tp_inst._defaults.minute < tp_inst._defaults.minuteMin? tp_inst._defaults.minuteMin : |
|
476 | 479 | return $("<option />").val(typeof val == "object" ? val.value : val).text(typeof val == "object" ? val.label : val); |
477 | 480 | })); |
478 | 481 | if (typeof(this.timezone) != "undefined" && this.timezone !== null && this.timezone !== "") { |
479 | | - var local_date = new Date(this.inst.selectedYear, this.inst.selectedMonth, this.inst.selectedDay, 12); |
480 | | - var local_timezone = $.timepicker.timezoneOffsetString(local_date.getTimezoneOffset(), this.support.iso8601); |
| 482 | + var local_timezone = (new Date(this.inst.selectedYear, this.inst.selectedMonth, this.inst.selectedDay, 12)).getTimezoneOffset()*-1; |
481 | 483 | if (local_timezone == this.timezone) { |
482 | 484 | selectLocalTimezone(tp_inst); |
483 | 485 | } else { |
|
1193 | 1195 | resTime.microsec = Number(treg[order.c]); |
1194 | 1196 | } |
1195 | 1197 | if (order.z !== -1 && treg[order.z] !== undefined) { |
1196 | | - var tz = treg[order.z].toUpperCase(); |
1197 | | - |
1198 | | - switch (tz.length) { |
1199 | | - case 1: |
1200 | | - // Z |
1201 | | - tz = iso8601 ? 'Z' : '+0000'; |
1202 | | - break; |
1203 | | - case 5: |
1204 | | - // +hhmm |
1205 | | - if (iso8601) { |
1206 | | - tz = tz.substring(1) == '0000' ? 'Z' : tz.substring(0, 3) + ':' + tz.substring(3); |
1207 | | - } |
1208 | | - break; |
1209 | | - case 6: |
1210 | | - // +hh:mm |
1211 | | - if (!iso8601) { |
1212 | | - tz = tz == 'Z' || tz.substring(1) == '00:00' ? '+0000' : tz.replace(/:/, ''); |
1213 | | - } else { |
1214 | | - if (tz.substring(1) == '00:00') { |
1215 | | - tz = 'Z'; |
1216 | | - } |
1217 | | - } |
1218 | | - break; |
1219 | | - } |
1220 | | - resTime.timezone = tz; |
| 1198 | + resTime.timezone = $.timepicker.timezoneOffsetNumber(treg[order.z]); |
1221 | 1199 | } |
1222 | 1200 |
|
1223 | 1201 |
|
|
1246 | 1224 | second: d.getSeconds(), |
1247 | 1225 | millisec: d.getMilliseconds(), |
1248 | 1226 | microsec: d.getMicroseconds(), |
1249 | | - timezone: $.timepicker.timezoneOffsetString(d.getTimezoneOffset(), iso8601) |
| 1227 | + timezone: d.getTimezoneOffset()*-1 |
1250 | 1228 | }; |
1251 | 1229 | } |
1252 | 1230 | catch(err){ |
|
1283 | 1261 | minute: 0, |
1284 | 1262 | second: 0, |
1285 | 1263 | millisec: 0, |
1286 | | - timezone: '+0000' |
| 1264 | + timezone: 0 |
1287 | 1265 | }, time); |
1288 | 1266 |
|
1289 | 1267 | var tmptime = format, |
|
1317 | 1295 | case 'c': |
1318 | 1296 | return ('00' + time.microsec).slice(-3); |
1319 | 1297 | case 'z': |
1320 | | - return time.timezone === null? options.timezone : time.timezone; |
| 1298 | + return $.timepicker.timezoneOffsetString(time.timezone === null? options.timezone : time.timezone, false); |
1321 | 1299 | case 'Z': |
1322 | | - return time.timezone === null? options.timezone : time.timezone; |
| 1300 | + return $.timepicker.timezoneOffsetString(time.timezone === null? options.timezone : time.timezone, true); |
1323 | 1301 | case 'T': |
1324 | 1302 | return ampmName.charAt(0).toUpperCase(); |
1325 | 1303 | case 'TT': |
|
1902 | 1880 | var selectLocalTimezone = function(tp_inst, date) { |
1903 | 1881 | if (tp_inst && tp_inst.timezone_select) { |
1904 | 1882 | var now = typeof date !== 'undefined' ? date : new Date(); |
1905 | | - var tzoffset = $.timepicker.timezoneOffsetString(now.getTimezoneOffset(), tp_inst.support.iso8601); |
1906 | | - tp_inst.timezone_select.val(tzoffset); |
| 1883 | + tp_inst.timezone_select.val(now.getTimezoneOffset()*-1); |
1907 | 1884 | } |
1908 | 1885 | }; |
1909 | 1886 |
|
|
1914 | 1891 |
|
1915 | 1892 | /** |
1916 | 1893 | * Get the timezone offset as string from a date object (eg '+0530' for UTC+5.5) |
1917 | | - * @param date |
| 1894 | + * @param number if not a number this value is returned |
1918 | 1895 | * @param boolean if true formats in accordance to iso8601 "+12:45" |
1919 | 1896 | * @return string |
1920 | 1897 | */ |
1921 | 1898 | $.timepicker.timezoneOffsetString = function(tzMinutes, iso8601) { |
1922 | | - var off = tzMinutes * -1, |
| 1899 | + if(isNaN(tzMinutes) || tzMinutes > 840){ |
| 1900 | + return tzMinutes; |
| 1901 | + } |
| 1902 | + |
| 1903 | + var off = tzMinutes, |
1923 | 1904 | minutes = off % 60, |
1924 | 1905 | hours = (off - minutes) / 60, |
1925 | 1906 | iso = iso8601? ':':'', |
|
1937 | 1918 | * @return number |
1938 | 1919 | */ |
1939 | 1920 | $.timepicker.timezoneOffsetNumber = function(tzString) { |
1940 | | - tzString = tzString.replace(/(\:|z)/gi,''); // excuse any iso8601, end up with "+1245" |
1941 | | - |
1942 | | - if(!/^(\-|\+)\d{4}$/.test(tzString)){ |
| 1921 | + tzString = tzString.toString().replace(':',''); // excuse any iso8601, end up with "+1245" |
| 1922 | + |
| 1923 | + if(tzString.toUpperCase() === 'Z'){ // if iso8601 with Z, its 0 minute offset |
1943 | 1924 | return 0; |
1944 | 1925 | } |
| 1926 | + |
| 1927 | + if(!/^(\-|\+)\d{4}$/.test(tzString)){ // possibly a user defined tz, so just give it back |
| 1928 | + return tzString; |
| 1929 | + } |
| 1930 | + |
1945 | 1931 | return ((tzString.substr(0,1) =='-'? -1 : 1) * // plus or minus |
1946 | 1932 | ((parseInt(tzString.substr(1,2),10)*60) + // hours (converted to minutes) |
1947 | 1933 | parseInt(tzString.substr(3,2),10))); // minutes |
|
1954 | 1940 | * @return date |
1955 | 1941 | */ |
1956 | 1942 | $.timepicker.timezoneAdjust = function(date, toTimezone) { |
1957 | | - var currTz = date.getTimezoneOffset(), |
1958 | | - toTz = $.timepicker.timezoneOffsetNumber(toTimezone)*-1, |
1959 | | - diff = currTz - toTz; // difference in minutes |
1960 | | - |
1961 | | - date.setMinutes(date.getMinutes()+diff); |
| 1943 | + var toTz = $.timepicker.timezoneOffsetNumber(toTimezone); |
| 1944 | + if(!isNaN(toTz)){ |
| 1945 | + var currTz = date.getTimezoneOffset()*-1, |
| 1946 | + diff = currTz - toTz; // difference in minutes |
1962 | 1947 |
|
| 1948 | + date.setMinutes(date.getMinutes()+diff); |
| 1949 | + } |
1963 | 1950 | return date; |
1964 | 1951 | }; |
1965 | 1952 |
|
|
0 commit comments