|
1 | 1 | /*
|
2 | 2 | * jQuery timepicker addon
|
3 | 3 | * By: Trent Richardson [http://trentrichardson.com]
|
4 |
| - * Version 1.3 |
5 |
| - * Last Modified: 05/05/2013 |
| 4 | + * Version 1.3.1 |
| 5 | + * Last Modified: 07/07/2013 |
6 | 6 | *
|
7 | 7 | * Copyright 2013 Trent Richardson
|
8 | 8 | * You may use this project under MIT or GPL licenses.
|
|
27 | 27 | */
|
28 | 28 | $.extend($.ui, {
|
29 | 29 | timepicker: {
|
30 |
| - version: "1.3" |
| 30 | + version: "1.3.1" |
31 | 31 | }
|
32 | 32 | });
|
33 | 33 |
|
|
163 | 163 | /*
|
164 | 164 | * Create a new Timepicker instance
|
165 | 165 | */
|
166 |
| - _newInst: function($input, o) { |
| 166 | + _newInst: function($input, opts) { |
167 | 167 | var tp_inst = new Timepicker(),
|
168 | 168 | inlineSettings = {},
|
169 | 169 | fns = {},
|
|
206 | 206 | };
|
207 | 207 | for (i in overrides) {
|
208 | 208 | if (overrides.hasOwnProperty(i)) {
|
209 |
| - fns[i] = o[i] || null; |
| 209 | + fns[i] = opts[i] || null; |
210 | 210 | }
|
211 | 211 | }
|
212 | 212 |
|
213 |
| - tp_inst._defaults = $.extend({}, this._defaults, inlineSettings, o, overrides, { |
| 213 | + tp_inst._defaults = $.extend({}, this._defaults, inlineSettings, opts, overrides, { |
214 | 214 | evnts:fns,
|
215 | 215 | timepicker: tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker');
|
216 | 216 | });
|
|
270 | 270 | tp_inst.ampm = '';
|
271 | 271 | tp_inst.$input = $input;
|
272 | 272 |
|
273 |
| - if (o.altField) { |
274 |
| - tp_inst.$altInput = $(o.altField).css({ |
| 273 | + if (tp_inst._defaults.altField) { |
| 274 | + tp_inst.$altInput = $(tp_inst._defaults.altField).css({ |
275 | 275 | cursor: 'pointer'
|
276 | 276 | }).focus(function() {
|
277 | 277 | $input.trigger("focus");
|
|
543 | 543 | }
|
544 | 544 | // end slideAccess integration
|
545 | 545 |
|
| 546 | + tp_inst._limitMinMaxDateTime(this.inst, true); |
546 | 547 | }
|
547 | 548 | },
|
548 | 549 |
|
|
824 | 825 | */
|
825 | 826 | _updateDateTime: function(dp_inst) {
|
826 | 827 | dp_inst = this.inst || dp_inst;
|
827 |
| - var dt = $.datepicker._daylightSavingAdjust(new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay)), |
| 828 | + //var dt = $.datepicker._daylightSavingAdjust(new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay)), |
| 829 | + var dt = $.datepicker._daylightSavingAdjust(new Date(dp_inst.currentYear, dp_inst.currentMonth, dp_inst.currentDay)), |
828 | 830 | dateFmt = $.datepicker._get(dp_inst, 'dateFormat'),
|
829 | 831 | formatCfg = $.datepicker._getFormatConfig(dp_inst),
|
830 | 832 | timeAvailable = dt !== null && this.timeDefined;
|
|
1076 | 1078 | if (parseRes.timeObj) {
|
1077 | 1079 | var t = parseRes.timeObj;
|
1078 | 1080 | parseRes.date.setHours(t.hour, t.minute, t.second, t.millisec);
|
1079 |
| - parseRex.date.setMicroseconds(t.microsec); |
| 1081 | + parseRes.date.setMicroseconds(t.microsec); |
1080 | 1082 | }
|
1081 | 1083 |
|
1082 | 1084 | return parseRes.date;
|
|
1546 | 1548 | tp_date.setMicroseconds(tp_inst.microsec);
|
1547 | 1549 | } else {
|
1548 | 1550 | tp_date = new Date(date.getTime());
|
| 1551 | + tp_date.setMicroseconds(date.getMicroseconds()); |
1549 | 1552 | }
|
1550 | 1553 | if (tp_date.toString() == 'Invalid Date') {
|
1551 | 1554 | tp_date = undefined;
|
|
1566 | 1569 | return;
|
1567 | 1570 | }
|
1568 | 1571 |
|
1569 |
| - var tp_inst = this._get(inst, 'timepicker'), |
1570 |
| - tp_date = (date instanceof Date) ? new Date(date.getTime()) : date; |
| 1572 | + if(typeof(date) === 'string'){ |
| 1573 | + date = new Date(date); |
| 1574 | + if(!date.getTime()){ |
| 1575 | + $.timepicker.log("Error creating Date object from string."); |
| 1576 | + } |
| 1577 | + } |
| 1578 | + |
| 1579 | + var tp_inst = this._get(inst, 'timepicker'); |
| 1580 | + var tp_date; |
| 1581 | + if (date instanceof Date) { |
| 1582 | + tp_date = new Date(date.getTime()); |
| 1583 | + tp_date.setMicroseconds(date.getMicroseconds()); |
| 1584 | + } else { |
| 1585 | + tp_date = date; |
| 1586 | + } |
1571 | 1587 |
|
1572 | 1588 | // This is important if you are using the timezone option, javascript's Date
|
1573 | 1589 | // object will only return the timezone offset for the current locale, so we
|
1574 | 1590 | // adjust it accordingly. If not using timezone option this won't matter..
|
1575 | 1591 | // If a timezone is different in tp, keep the timezone as is
|
1576 |
| - if(tp_inst && tp_inst.timezone != null){ |
| 1592 | + if(tp_inst){ |
| 1593 | + // look out for DST if tz wasn't specified |
| 1594 | + if(!tp_inst.support.timezone && tp_inst._defaults.timezone === null){ |
| 1595 | + tp_inst.timezone = tp_date.getTimezoneOffset()*-1; |
| 1596 | + } |
1577 | 1597 | date = $.timepicker.timezoneAdjust(date, tp_inst.timezone);
|
1578 | 1598 | tp_date = $.timepicker.timezoneAdjust(tp_date, tp_inst.timezone);
|
1579 | 1599 | }
|
|
1610 | 1630 | // object will only return the timezone offset for the current locale, so we
|
1611 | 1631 | // adjust it accordingly. If not using timezone option this won't matter..
|
1612 | 1632 | if(tp_inst.timezone != null){
|
| 1633 | + // look out for DST if tz wasn't specified |
| 1634 | + if(!tp_inst.support.timezone && tp_inst._defaults.timezone === null){ |
| 1635 | + tp_inst.timezone = date.getTimezoneOffset()*-1; |
| 1636 | + } |
1613 | 1637 | date = $.timepicker.timezoneAdjust(date, tp_inst.timezone);
|
1614 | 1638 | }
|
1615 | 1639 | }
|
|
1780 | 1804 | millisec: isIn(tf,'l'),
|
1781 | 1805 | microsec: isIn(tf,'c'),
|
1782 | 1806 | timezone: isIn(tf,'z'),
|
1783 |
| - ampm: isIn('t') && isIn(timeFormat,'h'), |
| 1807 | + ampm: isIn(tf,'t') && isIn(timeFormat,'h'), |
1784 | 1808 | iso8601: isIn(timeFormat, 'Z')
|
1785 | 1809 | };
|
1786 | 1810 | };
|
|
1944 | 1968 | $.timepicker.timezoneAdjust = function(date, toTimezone) {
|
1945 | 1969 | var toTz = $.timepicker.timezoneOffsetNumber(toTimezone);
|
1946 | 1970 | if(!isNaN(toTz)){
|
1947 |
| - var currTz = date.getTimezoneOffset()*-1, |
1948 |
| - diff = currTz - toTz; // difference in minutes |
1949 |
| - |
1950 |
| - date.setMinutes(date.getMinutes()+diff); |
| 1971 | + date.setMinutes(date.getMinutes()*1 + (date.getTimezoneOffset()*-1 - toTz*1) ); |
1951 | 1972 | }
|
1952 | 1973 | return date;
|
1953 | 1974 | };
|
|
2087 | 2108 | };
|
2088 | 2109 |
|
2089 | 2110 | /*
|
2090 |
| - * Rough microsecond support |
| 2111 | + * Microsecond support |
2091 | 2112 | */
|
2092 | 2113 | if(!Date.prototype.getMicroseconds){
|
2093 |
| - Date.microseconds = 0; |
| 2114 | + Date.prototype.microseconds = 0; |
2094 | 2115 | Date.prototype.getMicroseconds = function(){ return this.microseconds; };
|
2095 |
| - Date.prototype.setMicroseconds = function(m){ this.microseconds = m; return this; }; |
| 2116 | + Date.prototype.setMicroseconds = function(m){ |
| 2117 | + this.setMilliseconds(this.getMilliseconds() + Math.floor(m/1000)); |
| 2118 | + this.microseconds = m%1000; |
| 2119 | + return this; |
| 2120 | + }; |
2096 | 2121 | }
|
2097 | 2122 |
|
2098 | 2123 | /*
|
2099 | 2124 | * Keep up with the version
|
2100 | 2125 | */
|
2101 |
| - $.timepicker.version = "1.3"; |
| 2126 | + $.timepicker.version = "1.3.1"; |
2102 | 2127 |
|
2103 | 2128 | })(jQuery);
|
0 commit comments