jquery-ui-timepicker-addon.js 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203
  1. /*! jQuery Timepicker Addon - v1.4.5 - 2014-05-26
  2. * http://trentrichardson.com/examples/timepicker
  3. * Copyright (c) 2014 Trent Richardson; Licensed MIT */
  4. (function ($) {
  5. /*
  6. * Lets not redefine timepicker, Prevent "Uncaught RangeError: Maximum call stack size exceeded"
  7. */
  8. $.ui.timepicker = $.ui.timepicker || {};
  9. if ($.ui.timepicker.version) {
  10. return;
  11. }
  12. /*
  13. * Extend jQueryUI, get it started with our version number
  14. */
  15. $.extend($.ui, {
  16. timepicker: {
  17. version: "1.4.5"
  18. }
  19. });
  20. /*
  21. * Timepicker manager.
  22. * Use the singleton instance of this class, $.timepicker, to interact with the time picker.
  23. * Settings for (groups of) time pickers are maintained in an instance object,
  24. * allowing multiple different settings on the same page.
  25. */
  26. var Timepicker = function () {
  27. this.regional = []; // Available regional settings, indexed by language code
  28. this.regional[''] = { // Default regional settings
  29. currentText: 'Now',
  30. closeText: 'Done',
  31. amNames: ['AM', 'A'],
  32. pmNames: ['PM', 'P'],
  33. timeFormat: 'HH:mm',
  34. timeSuffix: '',
  35. timeOnlyTitle: 'Choose Time',
  36. timeText: 'Time',
  37. hourText: 'Hour',
  38. minuteText: 'Minute',
  39. secondText: 'Second',
  40. millisecText: 'Millisecond',
  41. microsecText: 'Microsecond',
  42. timezoneText: 'Time Zone',
  43. isRTL: false
  44. };
  45. this._defaults = { // Global defaults for all the datetime picker instances
  46. showButtonPanel: true,
  47. timeOnly: false,
  48. timeOnlyShowDate: false,
  49. showHour: null,
  50. showMinute: null,
  51. showSecond: null,
  52. showMillisec: null,
  53. showMicrosec: null,
  54. showTimezone: null,
  55. showTime: true,
  56. stepHour: 1,
  57. stepMinute: 1,
  58. stepSecond: 1,
  59. stepMillisec: 1,
  60. stepMicrosec: 1,
  61. hour: 0,
  62. minute: 0,
  63. second: 0,
  64. millisec: 0,
  65. microsec: 0,
  66. timezone: null,
  67. hourMin: 0,
  68. minuteMin: 0,
  69. secondMin: 0,
  70. millisecMin: 0,
  71. microsecMin: 0,
  72. hourMax: 23,
  73. minuteMax: 59,
  74. secondMax: 59,
  75. millisecMax: 999,
  76. microsecMax: 999,
  77. minDateTime: null,
  78. maxDateTime: null,
  79. maxTime: null,
  80. minTime: null,
  81. onSelect: null,
  82. hourGrid: 0,
  83. minuteGrid: 0,
  84. secondGrid: 0,
  85. millisecGrid: 0,
  86. microsecGrid: 0,
  87. alwaysSetTime: true,
  88. separator: ' ',
  89. altFieldTimeOnly: true,
  90. altTimeFormat: null,
  91. altSeparator: null,
  92. altTimeSuffix: null,
  93. altRedirectFocus: true,
  94. pickerTimeFormat: null,
  95. pickerTimeSuffix: null,
  96. showTimepicker: true,
  97. timezoneList: null,
  98. addSliderAccess: false,
  99. sliderAccessArgs: null,
  100. controlType: 'slider',
  101. defaultValue: null,
  102. parse: 'strict'
  103. };
  104. $.extend(this._defaults, this.regional['']);
  105. };
  106. $.extend(Timepicker.prototype, {
  107. $input: null,
  108. $altInput: null,
  109. $timeObj: null,
  110. inst: null,
  111. hour_slider: null,
  112. minute_slider: null,
  113. second_slider: null,
  114. millisec_slider: null,
  115. microsec_slider: null,
  116. timezone_select: null,
  117. maxTime: null,
  118. minTime: null,
  119. hour: 0,
  120. minute: 0,
  121. second: 0,
  122. millisec: 0,
  123. microsec: 0,
  124. timezone: null,
  125. hourMinOriginal: null,
  126. minuteMinOriginal: null,
  127. secondMinOriginal: null,
  128. millisecMinOriginal: null,
  129. microsecMinOriginal: null,
  130. hourMaxOriginal: null,
  131. minuteMaxOriginal: null,
  132. secondMaxOriginal: null,
  133. millisecMaxOriginal: null,
  134. microsecMaxOriginal: null,
  135. ampm: '',
  136. formattedDate: '',
  137. formattedTime: '',
  138. formattedDateTime: '',
  139. timezoneList: null,
  140. units: ['hour', 'minute', 'second', 'millisec', 'microsec'],
  141. support: {},
  142. control: null,
  143. /*
  144. * Override the default settings for all instances of the time picker.
  145. * @param {Object} settings object - the new settings to use as defaults (anonymous object)
  146. * @return {Object} the manager object
  147. */
  148. setDefaults: function (settings) {
  149. extendRemove(this._defaults, settings || {});
  150. return this;
  151. },
  152. /*
  153. * Create a new Timepicker instance
  154. */
  155. _newInst: function ($input, opts) {
  156. var tp_inst = new Timepicker(),
  157. inlineSettings = {},
  158. fns = {},
  159. overrides, i;
  160. for (var attrName in this._defaults) {
  161. if (this._defaults.hasOwnProperty(attrName)) {
  162. var attrValue = $input.attr('time:' + attrName);
  163. if (attrValue) {
  164. try {
  165. inlineSettings[attrName] = eval(attrValue);
  166. } catch (err) {
  167. inlineSettings[attrName] = attrValue;
  168. }
  169. }
  170. }
  171. }
  172. overrides = {
  173. beforeShow: function (input, dp_inst) {
  174. if ($.isFunction(tp_inst._defaults.evnts.beforeShow)) {
  175. return tp_inst._defaults.evnts.beforeShow.call($input[0], input, dp_inst, tp_inst);
  176. }
  177. },
  178. onChangeMonthYear: function (year, month, dp_inst) {
  179. // Update the time as well : this prevents the time from disappearing from the $input field.
  180. tp_inst._updateDateTime(dp_inst);
  181. if ($.isFunction(tp_inst._defaults.evnts.onChangeMonthYear)) {
  182. tp_inst._defaults.evnts.onChangeMonthYear.call($input[0], year, month, dp_inst, tp_inst);
  183. }
  184. },
  185. onClose: function (dateText, dp_inst) {
  186. if (tp_inst.timeDefined === true && $input.val() !== '') {
  187. tp_inst._updateDateTime(dp_inst);
  188. }
  189. if ($.isFunction(tp_inst._defaults.evnts.onClose)) {
  190. tp_inst._defaults.evnts.onClose.call($input[0], dateText, dp_inst, tp_inst);
  191. }
  192. }
  193. };
  194. for (i in overrides) {
  195. if (overrides.hasOwnProperty(i)) {
  196. fns[i] = opts[i] || null;
  197. }
  198. }
  199. tp_inst._defaults = $.extend({}, this._defaults, inlineSettings, opts, overrides, {
  200. evnts: fns,
  201. timepicker: tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker');
  202. });
  203. tp_inst.amNames = $.map(tp_inst._defaults.amNames, function (val) {
  204. return val.toUpperCase();
  205. });
  206. tp_inst.pmNames = $.map(tp_inst._defaults.pmNames, function (val) {
  207. return val.toUpperCase();
  208. });
  209. // detect which units are supported
  210. tp_inst.support = detectSupport(
  211. tp_inst._defaults.timeFormat +
  212. (tp_inst._defaults.pickerTimeFormat ? tp_inst._defaults.pickerTimeFormat : '') +
  213. (tp_inst._defaults.altTimeFormat ? tp_inst._defaults.altTimeFormat : ''));
  214. // controlType is string - key to our this._controls
  215. if (typeof(tp_inst._defaults.controlType) === 'string') {
  216. if (tp_inst._defaults.controlType === 'slider' && typeof($.ui.slider) === 'undefined') {
  217. tp_inst._defaults.controlType = 'select';
  218. }
  219. tp_inst.control = tp_inst._controls[tp_inst._defaults.controlType];
  220. }
  221. // controlType is an object and must implement create, options, value methods
  222. else {
  223. tp_inst.control = tp_inst._defaults.controlType;
  224. }
  225. // prep the timezone options
  226. var timezoneList = [-720, -660, -600, -570, -540, -480, -420, -360, -300, -270, -240, -210, -180, -120, -60,
  227. 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];
  228. if (tp_inst._defaults.timezoneList !== null) {
  229. timezoneList = tp_inst._defaults.timezoneList;
  230. }
  231. var tzl = timezoneList.length, tzi = 0, tzv = null;
  232. if (tzl > 0 && typeof timezoneList[0] !== 'object') {
  233. for (; tzi < tzl; tzi++) {
  234. tzv = timezoneList[tzi];
  235. timezoneList[tzi] = { value: tzv, label: $.timepicker.timezoneOffsetString(tzv, tp_inst.support.iso8601) };
  236. }
  237. }
  238. tp_inst._defaults.timezoneList = timezoneList;
  239. // set the default units
  240. tp_inst.timezone = tp_inst._defaults.timezone !== null ? $.timepicker.timezoneOffsetNumber(tp_inst._defaults.timezone) :
  241. ((new Date()).getTimezoneOffset() * -1);
  242. tp_inst.hour = tp_inst._defaults.hour < tp_inst._defaults.hourMin ? tp_inst._defaults.hourMin :
  243. tp_inst._defaults.hour > tp_inst._defaults.hourMax ? tp_inst._defaults.hourMax : tp_inst._defaults.hour;
  244. tp_inst.minute = tp_inst._defaults.minute < tp_inst._defaults.minuteMin ? tp_inst._defaults.minuteMin :
  245. tp_inst._defaults.minute > tp_inst._defaults.minuteMax ? tp_inst._defaults.minuteMax : tp_inst._defaults.minute;
  246. tp_inst.second = tp_inst._defaults.second < tp_inst._defaults.secondMin ? tp_inst._defaults.secondMin :
  247. tp_inst._defaults.second > tp_inst._defaults.secondMax ? tp_inst._defaults.secondMax : tp_inst._defaults.second;
  248. tp_inst.millisec = tp_inst._defaults.millisec < tp_inst._defaults.millisecMin ? tp_inst._defaults.millisecMin :
  249. tp_inst._defaults.millisec > tp_inst._defaults.millisecMax ? tp_inst._defaults.millisecMax : tp_inst._defaults.millisec;
  250. tp_inst.microsec = tp_inst._defaults.microsec < tp_inst._defaults.microsecMin ? tp_inst._defaults.microsecMin :
  251. tp_inst._defaults.microsec > tp_inst._defaults.microsecMax ? tp_inst._defaults.microsecMax : tp_inst._defaults.microsec;
  252. tp_inst.ampm = '';
  253. tp_inst.$input = $input;
  254. if (tp_inst._defaults.altField) {
  255. tp_inst.$altInput = $(tp_inst._defaults.altField);
  256. if (tp_inst._defaults.altRedirectFocus === true) {
  257. tp_inst.$altInput.css({
  258. cursor: 'pointer'
  259. }).focus(function () {
  260. $input.trigger("focus");
  261. });
  262. }
  263. }
  264. if (tp_inst._defaults.minDate === 0 || tp_inst._defaults.minDateTime === 0) {
  265. tp_inst._defaults.minDate = new Date();
  266. }
  267. if (tp_inst._defaults.maxDate === 0 || tp_inst._defaults.maxDateTime === 0) {
  268. tp_inst._defaults.maxDate = new Date();
  269. }
  270. // datepicker needs minDate/maxDate, timepicker needs minDateTime/maxDateTime..
  271. if (tp_inst._defaults.minDate !== undefined && tp_inst._defaults.minDate instanceof Date) {
  272. tp_inst._defaults.minDateTime = new Date(tp_inst._defaults.minDate.getTime());
  273. }
  274. if (tp_inst._defaults.minDateTime !== undefined && tp_inst._defaults.minDateTime instanceof Date) {
  275. tp_inst._defaults.minDate = new Date(tp_inst._defaults.minDateTime.getTime());
  276. }
  277. if (tp_inst._defaults.maxDate !== undefined && tp_inst._defaults.maxDate instanceof Date) {
  278. tp_inst._defaults.maxDateTime = new Date(tp_inst._defaults.maxDate.getTime());
  279. }
  280. if (tp_inst._defaults.maxDateTime !== undefined && tp_inst._defaults.maxDateTime instanceof Date) {
  281. tp_inst._defaults.maxDate = new Date(tp_inst._defaults.maxDateTime.getTime());
  282. }
  283. tp_inst.$input.bind('focus', function () {
  284. tp_inst._onFocus();
  285. });
  286. return tp_inst;
  287. },
  288. /*
  289. * add our sliders to the calendar
  290. */
  291. _addTimePicker: function (dp_inst) {
  292. var currDT = (this.$altInput && this._defaults.altFieldTimeOnly) ? this.$input.val() + ' ' + this.$altInput.val() : this.$input.val();
  293. this.timeDefined = this._parseTime(currDT);
  294. this._limitMinMaxDateTime(dp_inst, false);
  295. this._injectTimePicker();
  296. },
  297. /*
  298. * parse the time string from input value or _setTime
  299. */
  300. _parseTime: function (timeString, withDate) {
  301. if (!this.inst) {
  302. this.inst = $.datepicker._getInst(this.$input[0]);
  303. }
  304. if (withDate || !this._defaults.timeOnly) {
  305. var dp_dateFormat = $.datepicker._get(this.inst, 'dateFormat');
  306. try {
  307. var parseRes = parseDateTimeInternal(dp_dateFormat, this._defaults.timeFormat, timeString, $.datepicker._getFormatConfig(this.inst), this._defaults);
  308. if (!parseRes.timeObj) {
  309. return false;
  310. }
  311. $.extend(this, parseRes.timeObj);
  312. } catch (err) {
  313. $.timepicker.log("Error parsing the date/time string: " + err +
  314. "\ndate/time string = " + timeString +
  315. "\ntimeFormat = " + this._defaults.timeFormat +
  316. "\ndateFormat = " + dp_dateFormat);
  317. return false;
  318. }
  319. return true;
  320. } else {
  321. var timeObj = $.datepicker.parseTime(this._defaults.timeFormat, timeString, this._defaults);
  322. if (!timeObj) {
  323. return false;
  324. }
  325. $.extend(this, timeObj);
  326. return true;
  327. }
  328. },
  329. /*
  330. * generate and inject html for timepicker into ui datepicker
  331. */
  332. _injectTimePicker: function () {
  333. var $dp = this.inst.dpDiv,
  334. o = this.inst.settings,
  335. tp_inst = this,
  336. litem = '',
  337. uitem = '',
  338. show = null,
  339. max = {},
  340. gridSize = {},
  341. size = null,
  342. i = 0,
  343. l = 0;
  344. // Prevent displaying twice
  345. if ($dp.find("div.ui-timepicker-div").length === 0 && o.showTimepicker) {
  346. var noDisplay = ' style="display:none;"',
  347. html = '<div class="ui-timepicker-div' + (o.isRTL ? ' ui-timepicker-rtl' : '') + '"><dl>' + '<dt class="ui_tpicker_time_label"' + ((o.showTime) ? '' : noDisplay) + '>' + o.timeText + '</dt>' +
  348. '<dd class="ui_tpicker_time"' + ((o.showTime) ? '' : noDisplay) + '></dd>';
  349. // Create the markup
  350. for (i = 0, l = this.units.length; i < l; i++) {
  351. litem = this.units[i];
  352. uitem = litem.substr(0, 1).toUpperCase() + litem.substr(1);
  353. show = o['show' + uitem] !== null ? o['show' + uitem] : this.support[litem];
  354. // Added by Peter Medeiros:
  355. // - Figure out what the hour/minute/second max should be based on the step values.
  356. // - Example: if stepMinute is 15, then minMax is 45.
  357. max[litem] = parseInt((o[litem + 'Max'] - ((o[litem + 'Max'] - o[litem + 'Min']) % o['step' + uitem])), 10);
  358. gridSize[litem] = 0;
  359. html += '<dt class="ui_tpicker_' + litem + '_label"' + (show ? '' : noDisplay) + '>' + o[litem + 'Text'] + '</dt>' +
  360. '<dd class="ui_tpicker_' + litem + '"><div class="ui_tpicker_' + litem + '_slider"' + (show ? '' : noDisplay) + '></div>';
  361. if (show && o[litem + 'Grid'] > 0) {
  362. html += '<div style="padding-left: 1px"><table class="ui-tpicker-grid-label"><tr>';
  363. if (litem === 'hour') {
  364. for (var h = o[litem + 'Min']; h <= max[litem]; h += parseInt(o[litem + 'Grid'], 10)) {
  365. gridSize[litem]++;
  366. var tmph = $.datepicker.formatTime(this.support.ampm ? 'hht' : 'HH', {hour: h}, o);
  367. html += '<td data-for="' + litem + '">' + tmph + '</td>';
  368. }
  369. }
  370. else {
  371. for (var m = o[litem + 'Min']; m <= max[litem]; m += parseInt(o[litem + 'Grid'], 10)) {
  372. gridSize[litem]++;
  373. html += '<td data-for="' + litem + '">' + ((m < 10) ? '0' : '') + m + '</td>';
  374. }
  375. }
  376. html += '</tr></table></div>';
  377. }
  378. html += '</dd>';
  379. }
  380. // Timezone
  381. var showTz = o.showTimezone !== null ? o.showTimezone : this.support.timezone;
  382. html += '<dt class="ui_tpicker_timezone_label"' + (showTz ? '' : noDisplay) + '>' + o.timezoneText + '</dt>';
  383. html += '<dd class="ui_tpicker_timezone" ' + (showTz ? '' : noDisplay) + '></dd>';
  384. // Create the elements from string
  385. html += '</dl></div>';
  386. var $tp = $(html);
  387. // if we only want time picker...
  388. if (o.timeOnly === true) {
  389. $tp.prepend('<div class="ui-widget-header ui-helper-clearfix ui-corner-all">' + '<div class="ui-datepicker-title">' + o.timeOnlyTitle + '</div>' + '</div>');
  390. $dp.find('.ui-datepicker-header, .ui-datepicker-calendar').hide();
  391. }
  392. // add sliders, adjust grids, add events
  393. for (i = 0, l = tp_inst.units.length; i < l; i++) {
  394. litem = tp_inst.units[i];
  395. uitem = litem.substr(0, 1).toUpperCase() + litem.substr(1);
  396. show = o['show' + uitem] !== null ? o['show' + uitem] : this.support[litem];
  397. // add the slider
  398. tp_inst[litem + '_slider'] = tp_inst.control.create(tp_inst, $tp.find('.ui_tpicker_' + litem + '_slider'), litem, tp_inst[litem], o[litem + 'Min'], max[litem], o['step' + uitem]);
  399. // adjust the grid and add click event
  400. if (show && o[litem + 'Grid'] > 0) {
  401. size = 100 * gridSize[litem] * o[litem + 'Grid'] / (max[litem] - o[litem + 'Min']);
  402. $tp.find('.ui_tpicker_' + litem + ' table').css({
  403. width: size + "%",
  404. marginLeft: o.isRTL ? '0' : ((size / (-2 * gridSize[litem])) + "%"),
  405. marginRight: o.isRTL ? ((size / (-2 * gridSize[litem])) + "%") : '0',
  406. borderCollapse: 'collapse'
  407. }).find("td").click(function (e) {
  408. var $t = $(this),
  409. h = $t.html(),
  410. n = parseInt(h.replace(/[^0-9]/g), 10),
  411. ap = h.replace(/[^apm]/ig),
  412. f = $t.data('for'); // loses scope, so we use data-for
  413. if (f === 'hour') {
  414. if (ap.indexOf('p') !== -1 && n < 12) {
  415. n += 12;
  416. }
  417. else {
  418. if (ap.indexOf('a') !== -1 && n === 12) {
  419. n = 0;
  420. }
  421. }
  422. }
  423. tp_inst.control.value(tp_inst, tp_inst[f + '_slider'], litem, n);
  424. tp_inst._onTimeChange();
  425. tp_inst._onSelectHandler();
  426. }).css({
  427. cursor: 'pointer',
  428. width: (100 / gridSize[litem]) + '%',
  429. textAlign: 'center',
  430. overflow: 'hidden'
  431. });
  432. } // end if grid > 0
  433. } // end for loop
  434. // Add timezone options
  435. this.timezone_select = $tp.find('.ui_tpicker_timezone').append('<select></select>').find("select");
  436. $.fn.append.apply(this.timezone_select,
  437. $.map(o.timezoneList, function (val, idx) {
  438. return $("<option />").val(typeof val === "object" ? val.value : val).text(typeof val === "object" ? val.label : val);
  439. }));
  440. if (typeof(this.timezone) !== "undefined" && this.timezone !== null && this.timezone !== "") {
  441. var local_timezone = (new Date(this.inst.selectedYear, this.inst.selectedMonth, this.inst.selectedDay, 12)).getTimezoneOffset() * -1;
  442. if (local_timezone === this.timezone) {
  443. selectLocalTimezone(tp_inst);
  444. } else {
  445. this.timezone_select.val(this.timezone);
  446. }
  447. } else {
  448. if (typeof(this.hour) !== "undefined" && this.hour !== null && this.hour !== "") {
  449. this.timezone_select.val(o.timezone);
  450. } else {
  451. selectLocalTimezone(tp_inst);
  452. }
  453. }
  454. this.timezone_select.change(function () {
  455. tp_inst._onTimeChange();
  456. tp_inst._onSelectHandler();
  457. });
  458. // End timezone options
  459. // inject timepicker into datepicker
  460. var $buttonPanel = $dp.find('.ui-datepicker-buttonpane');
  461. if ($buttonPanel.length) {
  462. $buttonPanel.before($tp);
  463. } else {
  464. $dp.append($tp);
  465. }
  466. this.$timeObj = $tp.find('.ui_tpicker_time');
  467. if (this.inst !== null) {
  468. var timeDefined = this.timeDefined;
  469. this._onTimeChange();
  470. this.timeDefined = timeDefined;
  471. }
  472. // slideAccess integration: http://trentrichardson.com/2011/11/11/jquery-ui-sliders-and-touch-accessibility/
  473. if (this._defaults.addSliderAccess) {
  474. var sliderAccessArgs = this._defaults.sliderAccessArgs,
  475. rtl = this._defaults.isRTL;
  476. sliderAccessArgs.isRTL = rtl;
  477. setTimeout(function () { // fix for inline mode
  478. if ($tp.find('.ui-slider-access').length === 0) {
  479. $tp.find('.ui-slider:visible').sliderAccess(sliderAccessArgs);
  480. // fix any grids since sliders are shorter
  481. var sliderAccessWidth = $tp.find('.ui-slider-access:eq(0)').outerWidth(true);
  482. if (sliderAccessWidth) {
  483. $tp.find('table:visible').each(function () {
  484. var $g = $(this),
  485. oldWidth = $g.outerWidth(),
  486. oldMarginLeft = $g.css(rtl ? 'marginRight' : 'marginLeft').toString().replace('%', ''),
  487. newWidth = oldWidth - sliderAccessWidth,
  488. newMarginLeft = ((oldMarginLeft * newWidth) / oldWidth) + '%',
  489. css = { width: newWidth, marginRight: 0, marginLeft: 0 };
  490. css[rtl ? 'marginRight' : 'marginLeft'] = newMarginLeft;
  491. $g.css(css);
  492. });
  493. }
  494. }
  495. }, 10);
  496. }
  497. // end slideAccess integration
  498. tp_inst._limitMinMaxDateTime(this.inst, true);
  499. }
  500. },
  501. /*
  502. * This function tries to limit the ability to go outside the
  503. * min/max date range
  504. */
  505. _limitMinMaxDateTime: function (dp_inst, adjustSliders) {
  506. var o = this._defaults,
  507. dp_date = new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay);
  508. if (!this._defaults.showTimepicker) {
  509. return;
  510. } // No time so nothing to check here
  511. if ($.datepicker._get(dp_inst, 'minDateTime') !== null && $.datepicker._get(dp_inst, 'minDateTime') !== undefined && dp_date) {
  512. var minDateTime = $.datepicker._get(dp_inst, 'minDateTime'),
  513. minDateTimeDate = new Date(minDateTime.getFullYear(), minDateTime.getMonth(), minDateTime.getDate(), 0, 0, 0, 0);
  514. if (this.hourMinOriginal === null || this.minuteMinOriginal === null || this.secondMinOriginal === null || this.millisecMinOriginal === null || this.microsecMinOriginal === null) {
  515. this.hourMinOriginal = o.hourMin;
  516. this.minuteMinOriginal = o.minuteMin;
  517. this.secondMinOriginal = o.secondMin;
  518. this.millisecMinOriginal = o.millisecMin;
  519. this.microsecMinOriginal = o.microsecMin;
  520. }
  521. if (dp_inst.settings.timeOnly || minDateTimeDate.getTime() === dp_date.getTime()) {
  522. this._defaults.hourMin = minDateTime.getHours();
  523. if (this.hour <= this._defaults.hourMin) {
  524. this.hour = this._defaults.hourMin;
  525. this._defaults.minuteMin = minDateTime.getMinutes();
  526. if (this.minute <= this._defaults.minuteMin) {
  527. this.minute = this._defaults.minuteMin;
  528. this._defaults.secondMin = minDateTime.getSeconds();
  529. if (this.second <= this._defaults.secondMin) {
  530. this.second = this._defaults.secondMin;
  531. this._defaults.millisecMin = minDateTime.getMilliseconds();
  532. if (this.millisec <= this._defaults.millisecMin) {
  533. this.millisec = this._defaults.millisecMin;
  534. this._defaults.microsecMin = minDateTime.getMicroseconds();
  535. } else {
  536. if (this.microsec < this._defaults.microsecMin) {
  537. this.microsec = this._defaults.microsecMin;
  538. }
  539. this._defaults.microsecMin = this.microsecMinOriginal;
  540. }
  541. } else {
  542. this._defaults.millisecMin = this.millisecMinOriginal;
  543. this._defaults.microsecMin = this.microsecMinOriginal;
  544. }
  545. } else {
  546. this._defaults.secondMin = this.secondMinOriginal;
  547. this._defaults.millisecMin = this.millisecMinOriginal;
  548. this._defaults.microsecMin = this.microsecMinOriginal;
  549. }
  550. } else {
  551. this._defaults.minuteMin = this.minuteMinOriginal;
  552. this._defaults.secondMin = this.secondMinOriginal;
  553. this._defaults.millisecMin = this.millisecMinOriginal;
  554. this._defaults.microsecMin = this.microsecMinOriginal;
  555. }
  556. } else {
  557. this._defaults.hourMin = this.hourMinOriginal;
  558. this._defaults.minuteMin = this.minuteMinOriginal;
  559. this._defaults.secondMin = this.secondMinOriginal;
  560. this._defaults.millisecMin = this.millisecMinOriginal;
  561. this._defaults.microsecMin = this.microsecMinOriginal;
  562. }
  563. }
  564. if ($.datepicker._get(dp_inst, 'maxDateTime') !== null && $.datepicker._get(dp_inst, 'maxDateTime') !== undefined && dp_date) {
  565. var maxDateTime = $.datepicker._get(dp_inst, 'maxDateTime'),
  566. maxDateTimeDate = new Date(maxDateTime.getFullYear(), maxDateTime.getMonth(), maxDateTime.getDate(), 0, 0, 0, 0);
  567. if (this.hourMaxOriginal === null || this.minuteMaxOriginal === null || this.secondMaxOriginal === null || this.millisecMaxOriginal === null) {
  568. this.hourMaxOriginal = o.hourMax;
  569. this.minuteMaxOriginal = o.minuteMax;
  570. this.secondMaxOriginal = o.secondMax;
  571. this.millisecMaxOriginal = o.millisecMax;
  572. this.microsecMaxOriginal = o.microsecMax;
  573. }
  574. if (dp_inst.settings.timeOnly || maxDateTimeDate.getTime() === dp_date.getTime()) {
  575. this._defaults.hourMax = maxDateTime.getHours();
  576. if (this.hour >= this._defaults.hourMax) {
  577. this.hour = this._defaults.hourMax;
  578. this._defaults.minuteMax = maxDateTime.getMinutes();
  579. if (this.minute >= this._defaults.minuteMax) {
  580. this.minute = this._defaults.minuteMax;
  581. this._defaults.secondMax = maxDateTime.getSeconds();
  582. if (this.second >= this._defaults.secondMax) {
  583. this.second = this._defaults.secondMax;
  584. this._defaults.millisecMax = maxDateTime.getMilliseconds();
  585. if (this.millisec >= this._defaults.millisecMax) {
  586. this.millisec = this._defaults.millisecMax;
  587. this._defaults.microsecMax = maxDateTime.getMicroseconds();
  588. } else {
  589. if (this.microsec > this._defaults.microsecMax) {
  590. this.microsec = this._defaults.microsecMax;
  591. }
  592. this._defaults.microsecMax = this.microsecMaxOriginal;
  593. }
  594. } else {
  595. this._defaults.millisecMax = this.millisecMaxOriginal;
  596. this._defaults.microsecMax = this.microsecMaxOriginal;
  597. }
  598. } else {
  599. this._defaults.secondMax = this.secondMaxOriginal;
  600. this._defaults.millisecMax = this.millisecMaxOriginal;
  601. this._defaults.microsecMax = this.microsecMaxOriginal;
  602. }
  603. } else {
  604. this._defaults.minuteMax = this.minuteMaxOriginal;
  605. this._defaults.secondMax = this.secondMaxOriginal;
  606. this._defaults.millisecMax = this.millisecMaxOriginal;
  607. this._defaults.microsecMax = this.microsecMaxOriginal;
  608. }
  609. } else {
  610. this._defaults.hourMax = this.hourMaxOriginal;
  611. this._defaults.minuteMax = this.minuteMaxOriginal;
  612. this._defaults.secondMax = this.secondMaxOriginal;
  613. this._defaults.millisecMax = this.millisecMaxOriginal;
  614. this._defaults.microsecMax = this.microsecMaxOriginal;
  615. }
  616. }
  617. if (dp_inst.settings.minTime!==null) {
  618. var tempMinTime=new Date("01/01/1970 " + dp_inst.settings.minTime);
  619. if (this.hour<tempMinTime.getHours()) {
  620. this.hour=this._defaults.hourMin=tempMinTime.getHours();
  621. this.minute=this._defaults.minuteMin=tempMinTime.getMinutes();
  622. } else if (this.hour===tempMinTime.getHours() && this.minute<tempMinTime.getMinutes()) {
  623. this.minute=this._defaults.minuteMin=tempMinTime.getMinutes();
  624. } else {
  625. if (this._defaults.hourMin<tempMinTime.getHours()) {
  626. this._defaults.hourMin=tempMinTime.getHours();
  627. this._defaults.minuteMin=tempMinTime.getMinutes();
  628. } else if (this._defaults.hourMin===tempMinTime.getHours()===this.hour && this._defaults.minuteMin<tempMinTime.getMinutes()) {
  629. this._defaults.minuteMin=tempMinTime.getMinutes();
  630. } else {
  631. this._defaults.minuteMin=0;
  632. }
  633. }
  634. }
  635. if (dp_inst.settings.maxTime!==null) {
  636. var tempMaxTime=new Date("01/01/1970 " + dp_inst.settings.maxTime);
  637. if (this.hour>tempMaxTime.getHours()) {
  638. this.hour=this._defaults.hourMax=tempMaxTime.getHours();
  639. this.minute=this._defaults.minuteMax=tempMaxTime.getMinutes();
  640. } else if (this.hour===tempMaxTime.getHours() && this.minute>tempMaxTime.getMinutes()) {
  641. this.minute=this._defaults.minuteMax=tempMaxTime.getMinutes();
  642. } else {
  643. if (this._defaults.hourMax>tempMaxTime.getHours()) {
  644. this._defaults.hourMax=tempMaxTime.getHours();
  645. this._defaults.minuteMax=tempMaxTime.getMinutes();
  646. } else if (this._defaults.hourMax===tempMaxTime.getHours()===this.hour && this._defaults.minuteMax>tempMaxTime.getMinutes()) {
  647. this._defaults.minuteMax=tempMaxTime.getMinutes();
  648. } else {
  649. this._defaults.minuteMax=59;
  650. }
  651. }
  652. }
  653. if (adjustSliders !== undefined && adjustSliders === true) {
  654. var hourMax = parseInt((this._defaults.hourMax - ((this._defaults.hourMax - this._defaults.hourMin) % this._defaults.stepHour)), 10),
  655. minMax = parseInt((this._defaults.minuteMax - ((this._defaults.minuteMax - this._defaults.minuteMin) % this._defaults.stepMinute)), 10),
  656. secMax = parseInt((this._defaults.secondMax - ((this._defaults.secondMax - this._defaults.secondMin) % this._defaults.stepSecond)), 10),
  657. millisecMax = parseInt((this._defaults.millisecMax - ((this._defaults.millisecMax - this._defaults.millisecMin) % this._defaults.stepMillisec)), 10),
  658. microsecMax = parseInt((this._defaults.microsecMax - ((this._defaults.microsecMax - this._defaults.microsecMin) % this._defaults.stepMicrosec)), 10);
  659. if (this.hour_slider) {
  660. this.control.options(this, this.hour_slider, 'hour', { min: this._defaults.hourMin, max: hourMax, step: this._defaults.stepHour });
  661. this.control.value(this, this.hour_slider, 'hour', this.hour - (this.hour % this._defaults.stepHour));
  662. }
  663. if (this.minute_slider) {
  664. this.control.options(this, this.minute_slider, 'minute', { min: this._defaults.minuteMin, max: minMax, step: this._defaults.stepMinute });
  665. this.control.value(this, this.minute_slider, 'minute', this.minute - (this.minute % this._defaults.stepMinute));
  666. }
  667. if (this.second_slider) {
  668. this.control.options(this, this.second_slider, 'second', { min: this._defaults.secondMin, max: secMax, step: this._defaults.stepSecond });
  669. this.control.value(this, this.second_slider, 'second', this.second - (this.second % this._defaults.stepSecond));
  670. }
  671. if (this.millisec_slider) {
  672. this.control.options(this, this.millisec_slider, 'millisec', { min: this._defaults.millisecMin, max: millisecMax, step: this._defaults.stepMillisec });
  673. this.control.value(this, this.millisec_slider, 'millisec', this.millisec - (this.millisec % this._defaults.stepMillisec));
  674. }
  675. if (this.microsec_slider) {
  676. this.control.options(this, this.microsec_slider, 'microsec', { min: this._defaults.microsecMin, max: microsecMax, step: this._defaults.stepMicrosec });
  677. this.control.value(this, this.microsec_slider, 'microsec', this.microsec - (this.microsec % this._defaults.stepMicrosec));
  678. }
  679. }
  680. },
  681. /*
  682. * when a slider moves, set the internal time...
  683. * on time change is also called when the time is updated in the text field
  684. */
  685. _onTimeChange: function () {
  686. if (!this._defaults.showTimepicker) {
  687. return;
  688. }
  689. var hour = (this.hour_slider) ? this.control.value(this, this.hour_slider, 'hour') : false,
  690. minute = (this.minute_slider) ? this.control.value(this, this.minute_slider, 'minute') : false,
  691. second = (this.second_slider) ? this.control.value(this, this.second_slider, 'second') : false,
  692. millisec = (this.millisec_slider) ? this.control.value(this, this.millisec_slider, 'millisec') : false,
  693. microsec = (this.microsec_slider) ? this.control.value(this, this.microsec_slider, 'microsec') : false,
  694. timezone = (this.timezone_select) ? this.timezone_select.val() : false,
  695. o = this._defaults,
  696. pickerTimeFormat = o.pickerTimeFormat || o.timeFormat,
  697. pickerTimeSuffix = o.pickerTimeSuffix || o.timeSuffix;
  698. if (typeof(hour) === 'object') {
  699. hour = false;
  700. }
  701. if (typeof(minute) === 'object') {
  702. minute = false;
  703. }
  704. if (typeof(second) === 'object') {
  705. second = false;
  706. }
  707. if (typeof(millisec) === 'object') {
  708. millisec = false;
  709. }
  710. if (typeof(microsec) === 'object') {
  711. microsec = false;
  712. }
  713. if (typeof(timezone) === 'object') {
  714. timezone = false;
  715. }
  716. if (hour !== false) {
  717. hour = parseInt(hour, 10);
  718. }
  719. if (minute !== false) {
  720. minute = parseInt(minute, 10);
  721. }
  722. if (second !== false) {
  723. second = parseInt(second, 10);
  724. }
  725. if (millisec !== false) {
  726. millisec = parseInt(millisec, 10);
  727. }
  728. if (microsec !== false) {
  729. microsec = parseInt(microsec, 10);
  730. }
  731. if (timezone !== false) {
  732. timezone = timezone.toString();
  733. }
  734. var ampm = o[hour < 12 ? 'amNames' : 'pmNames'][0];
  735. // If the update was done in the input field, the input field should not be updated.
  736. // If the update was done using the sliders, update the input field.
  737. var hasChanged = (
  738. hour !== parseInt(this.hour,10) || // sliders should all be numeric
  739. minute !== parseInt(this.minute,10) ||
  740. second !== parseInt(this.second,10) ||
  741. millisec !== parseInt(this.millisec,10) ||
  742. microsec !== parseInt(this.microsec,10) ||
  743. (this.ampm.length > 0 && (hour < 12) !== ($.inArray(this.ampm.toUpperCase(), this.amNames) !== -1)) ||
  744. (this.timezone !== null && timezone !== this.timezone.toString()) // could be numeric or "EST" format, so use toString()
  745. );
  746. if (hasChanged) {
  747. if (hour !== false) {
  748. this.hour = hour;
  749. }
  750. if (minute !== false) {
  751. this.minute = minute;
  752. }
  753. if (second !== false) {
  754. this.second = second;
  755. }
  756. if (millisec !== false) {
  757. this.millisec = millisec;
  758. }
  759. if (microsec !== false) {
  760. this.microsec = microsec;
  761. }
  762. if (timezone !== false) {
  763. this.timezone = timezone;
  764. }
  765. if (!this.inst) {
  766. this.inst = $.datepicker._getInst(this.$input[0]);
  767. }
  768. this._limitMinMaxDateTime(this.inst, true);
  769. }
  770. if (this.support.ampm) {
  771. this.ampm = ampm;
  772. }
  773. // Updates the time within the timepicker
  774. this.formattedTime = $.datepicker.formatTime(o.timeFormat, this, o);
  775. if (this.$timeObj) {
  776. if (pickerTimeFormat === o.timeFormat) {
  777. this.$timeObj.text(this.formattedTime + pickerTimeSuffix);
  778. }
  779. else {
  780. this.$timeObj.text($.datepicker.formatTime(pickerTimeFormat, this, o) + pickerTimeSuffix);
  781. }
  782. }
  783. this.timeDefined = true;
  784. if (hasChanged) {
  785. this._updateDateTime();
  786. //this.$input.focus(); // may automatically open the picker on setDate
  787. }
  788. },
  789. /*
  790. * call custom onSelect.
  791. * bind to sliders slidestop, and grid click.
  792. */
  793. _onSelectHandler: function () {
  794. var onSelect = this._defaults.onSelect || this.inst.settings.onSelect;
  795. var inputEl = this.$input ? this.$input[0] : null;
  796. if (onSelect && inputEl) {
  797. onSelect.apply(inputEl, [this.formattedDateTime, this]);
  798. }
  799. },
  800. /*
  801. * update our input with the new date time..
  802. */
  803. _updateDateTime: function (dp_inst) {
  804. dp_inst = this.inst || dp_inst;
  805. var dtTmp = (dp_inst.currentYear > 0?
  806. new Date(dp_inst.currentYear, dp_inst.currentMonth, dp_inst.currentDay) :
  807. new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay)),
  808. dt = $.datepicker._daylightSavingAdjust(dtTmp),
  809. //dt = $.datepicker._daylightSavingAdjust(new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay)),
  810. //dt = $.datepicker._daylightSavingAdjust(new Date(dp_inst.currentYear, dp_inst.currentMonth, dp_inst.currentDay)),
  811. dateFmt = $.datepicker._get(dp_inst, 'dateFormat'),
  812. formatCfg = $.datepicker._getFormatConfig(dp_inst),
  813. timeAvailable = dt !== null && this.timeDefined;
  814. this.formattedDate = $.datepicker.formatDate(dateFmt, (dt === null ? new Date() : dt), formatCfg);
  815. var formattedDateTime = this.formattedDate;
  816. // if a slider was changed but datepicker doesn't have a value yet, set it
  817. if (dp_inst.lastVal === "") {
  818. dp_inst.currentYear = dp_inst.selectedYear;
  819. dp_inst.currentMonth = dp_inst.selectedMonth;
  820. dp_inst.currentDay = dp_inst.selectedDay;
  821. }
  822. /*
  823. * remove following lines to force every changes in date picker to change the input value
  824. * Bug descriptions: when an input field has a default value, and click on the field to pop up the date picker.
  825. * If the user manually empty the value in the input field, the date picker will never change selected value.
  826. */
  827. //if (dp_inst.lastVal !== undefined && (dp_inst.lastVal.length > 0 && this.$input.val().length === 0)) {
  828. // return;
  829. //}
  830. if (this._defaults.timeOnly === true && this._defaults.timeOnlyShowDate === false) {
  831. formattedDateTime = this.formattedTime;
  832. } else if ((this._defaults.timeOnly !== true && (this._defaults.alwaysSetTime || timeAvailable)) || (this._defaults.timeOnly === true && this._defaults.timeOnlyShowDate === true)) {
  833. formattedDateTime += this._defaults.separator + this.formattedTime + this._defaults.timeSuffix;
  834. }
  835. this.formattedDateTime = formattedDateTime;
  836. if (!this._defaults.showTimepicker) {
  837. this.$input.val(this.formattedDate);
  838. } else if (this.$altInput && this._defaults.timeOnly === false && this._defaults.altFieldTimeOnly === true) {
  839. this.$altInput.val(this.formattedTime);
  840. this.$input.val(this.formattedDate);
  841. } else if (this.$altInput) {
  842. this.$input.val(formattedDateTime);
  843. var altFormattedDateTime = '',
  844. altSeparator = this._defaults.altSeparator !== null ? this._defaults.altSeparator : this._defaults.separator,
  845. altTimeSuffix = this._defaults.altTimeSuffix !== null ? this._defaults.altTimeSuffix : this._defaults.timeSuffix;
  846. if (!this._defaults.timeOnly) {
  847. if (this._defaults.altFormat) {
  848. altFormattedDateTime = $.datepicker.formatDate(this._defaults.altFormat, (dt === null ? new Date() : dt), formatCfg);
  849. }
  850. else {
  851. altFormattedDateTime = this.formattedDate;
  852. }
  853. if (altFormattedDateTime) {
  854. altFormattedDateTime += altSeparator;
  855. }
  856. }
  857. if (this._defaults.altTimeFormat !== null) {
  858. altFormattedDateTime += $.datepicker.formatTime(this._defaults.altTimeFormat, this, this._defaults) + altTimeSuffix;
  859. }
  860. else {
  861. altFormattedDateTime += this.formattedTime + altTimeSuffix;
  862. }
  863. this.$altInput.val(altFormattedDateTime);
  864. } else {
  865. this.$input.val(formattedDateTime);
  866. }
  867. this.$input.trigger("change");
  868. },
  869. _onFocus: function () {
  870. if (!this.$input.val() && this._defaults.defaultValue) {
  871. this.$input.val(this._defaults.defaultValue);
  872. var inst = $.datepicker._getInst(this.$input.get(0)),
  873. tp_inst = $.datepicker._get(inst, 'timepicker');
  874. if (tp_inst) {
  875. if (tp_inst._defaults.timeOnly && (inst.input.val() !== inst.lastVal)) {
  876. try {
  877. $.datepicker._updateDatepicker(inst);
  878. } catch (err) {
  879. $.timepicker.log(err);
  880. }
  881. }
  882. }
  883. }
  884. },
  885. /*
  886. * Small abstraction to control types
  887. * We can add more, just be sure to follow the pattern: create, options, value
  888. */
  889. _controls: {
  890. // slider methods
  891. slider: {
  892. create: function (tp_inst, obj, unit, val, min, max, step) {
  893. var rtl = tp_inst._defaults.isRTL; // if rtl go -60->0 instead of 0->60
  894. return obj.prop('slide', null).slider({
  895. orientation: "horizontal",
  896. value: rtl ? val * -1 : val,
  897. min: rtl ? max * -1 : min,
  898. max: rtl ? min * -1 : max,
  899. step: step,
  900. slide: function (event, ui) {
  901. tp_inst.control.value(tp_inst, $(this), unit, rtl ? ui.value * -1 : ui.value);
  902. tp_inst._onTimeChange();
  903. },
  904. stop: function (event, ui) {
  905. tp_inst._onSelectHandler();
  906. }
  907. });
  908. },
  909. options: function (tp_inst, obj, unit, opts, val) {
  910. if (tp_inst._defaults.isRTL) {
  911. if (typeof(opts) === 'string') {
  912. if (opts === 'min' || opts === 'max') {
  913. if (val !== undefined) {
  914. return obj.slider(opts, val * -1);
  915. }
  916. return Math.abs(obj.slider(opts));
  917. }
  918. return obj.slider(opts);
  919. }
  920. var min = opts.min,
  921. max = opts.max;
  922. opts.min = opts.max = null;
  923. if (min !== undefined) {
  924. opts.max = min * -1;
  925. }
  926. if (max !== undefined) {
  927. opts.min = max * -1;
  928. }
  929. return obj.slider(opts);
  930. }
  931. if (typeof(opts) === 'string' && val !== undefined) {
  932. return obj.slider(opts, val);
  933. }
  934. return obj.slider(opts);
  935. },
  936. value: function (tp_inst, obj, unit, val) {
  937. if (tp_inst._defaults.isRTL) {
  938. if (val !== undefined) {
  939. return obj.slider('value', val * -1);
  940. }
  941. return Math.abs(obj.slider('value'));
  942. }
  943. if (val !== undefined) {
  944. return obj.slider('value', val);
  945. }
  946. return obj.slider('value');
  947. }
  948. },
  949. // select methods
  950. select: {
  951. create: function (tp_inst, obj, unit, val, min, max, step) {
  952. var sel = '<select class="ui-timepicker-select" data-unit="' + unit + '" data-min="' + min + '" data-max="' + max + '" data-step="' + step + '">',
  953. format = tp_inst._defaults.pickerTimeFormat || tp_inst._defaults.timeFormat;
  954. for (var i = min; i <= max; i += step) {
  955. sel += '<option value="' + i + '"' + (i === val ? ' selected' : '') + '>';
  956. if (unit === 'hour') {
  957. sel += $.datepicker.formatTime($.trim(format.replace(/[^ht ]/ig, '')), {hour: i}, tp_inst._defaults);
  958. }
  959. else if (unit === 'millisec' || unit === 'microsec' || i >= 10) { sel += i; }
  960. else {sel += '0' + i.toString(); }
  961. sel += '</option>';
  962. }
  963. sel += '</select>';
  964. obj.children('select').remove();
  965. $(sel).appendTo(obj).change(function (e) {
  966. tp_inst._onTimeChange();
  967. tp_inst._onSelectHandler();
  968. });
  969. return obj;
  970. },
  971. options: function (tp_inst, obj, unit, opts, val) {
  972. var o = {},
  973. $t = obj.children('select');
  974. if (typeof(opts) === 'string') {
  975. if (val === undefined) {
  976. return $t.data(opts);
  977. }
  978. o[opts] = val;
  979. }
  980. else { o = opts; }
  981. return tp_inst.control.create(tp_inst, obj, $t.data('unit'), $t.val(), o.min || $t.data('min'), o.max || $t.data('max'), o.step || $t.data('step'));
  982. },
  983. value: function (tp_inst, obj, unit, val) {
  984. var $t = obj.children('select');
  985. if (val !== undefined) {
  986. return $t.val(val);
  987. }
  988. return $t.val();
  989. }
  990. }
  991. } // end _controls
  992. });
  993. $.fn.extend({
  994. /*
  995. * shorthand just to use timepicker.
  996. */
  997. timepicker: function (o) {
  998. o = o || {};
  999. var tmp_args = Array.prototype.slice.call(arguments);
  1000. if (typeof o === 'object') {
  1001. tmp_args[0] = $.extend(o, {
  1002. timeOnly: true
  1003. });
  1004. }
  1005. return $(this).each(function () {
  1006. $.fn.datetimepicker.apply($(this), tmp_args);
  1007. });
  1008. },
  1009. /*
  1010. * extend timepicker to datepicker
  1011. */
  1012. datetimepicker: function (o) {
  1013. o = o || {};
  1014. var tmp_args = arguments;
  1015. if (typeof(o) === 'string') {
  1016. if (o === 'getDate' || (o === 'option' && tmp_args.length === 2 && typeof (tmp_args[1]) === 'string')) {
  1017. return $.fn.datepicker.apply($(this[0]), tmp_args);
  1018. } else {
  1019. return this.each(function () {
  1020. var $t = $(this);
  1021. $t.datepicker.apply($t, tmp_args);
  1022. });
  1023. }
  1024. } else {
  1025. return this.each(function () {
  1026. var $t = $(this);
  1027. $t.datepicker($.timepicker._newInst($t, o)._defaults);
  1028. });
  1029. }
  1030. }
  1031. });
  1032. /*
  1033. * Public Utility to parse date and time
  1034. */
  1035. $.datepicker.parseDateTime = function (dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings) {
  1036. var parseRes = parseDateTimeInternal(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings);
  1037. if (parseRes.timeObj) {
  1038. var t = parseRes.timeObj;
  1039. parseRes.date.setHours(t.hour, t.minute, t.second, t.millisec);
  1040. parseRes.date.setMicroseconds(t.microsec);
  1041. }
  1042. return parseRes.date;
  1043. };
  1044. /*
  1045. * Public utility to parse time
  1046. */
  1047. $.datepicker.parseTime = function (timeFormat, timeString, options) {
  1048. var o = extendRemove(extendRemove({}, $.timepicker._defaults), options || {}),
  1049. iso8601 = (timeFormat.replace(/\'.*?\'/g, '').indexOf('Z') !== -1);
  1050. // Strict parse requires the timeString to match the timeFormat exactly
  1051. var strictParse = function (f, s, o) {
  1052. // pattern for standard and localized AM/PM markers
  1053. var getPatternAmpm = function (amNames, pmNames) {
  1054. var markers = [];
  1055. if (amNames) {
  1056. $.merge(markers, amNames);
  1057. }
  1058. if (pmNames) {
  1059. $.merge(markers, pmNames);
  1060. }
  1061. markers = $.map(markers, function (val) {
  1062. return val.replace(/[.*+?|()\[\]{}\\]/g, '\\$&');
  1063. });
  1064. return '(' + markers.join('|') + ')?';
  1065. };
  1066. // figure out position of time elements.. cause js cant do named captures
  1067. var getFormatPositions = function (timeFormat) {
  1068. var finds = timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|l{1}|c{1}|t{1,2}|z|'.*?')/g),
  1069. orders = {
  1070. h: -1,
  1071. m: -1,
  1072. s: -1,
  1073. l: -1,
  1074. c: -1,
  1075. t: -1,
  1076. z: -1
  1077. };
  1078. if (finds) {
  1079. for (var i = 0; i < finds.length; i++) {
  1080. if (orders[finds[i].toString().charAt(0)] === -1) {
  1081. orders[finds[i].toString().charAt(0)] = i + 1;
  1082. }
  1083. }
  1084. }
  1085. return orders;
  1086. };
  1087. var regstr = '^' + f.toString()
  1088. .replace(/([hH]{1,2}|mm?|ss?|[tT]{1,2}|[zZ]|[lc]|'.*?')/g, function (match) {
  1089. var ml = match.length;
  1090. switch (match.charAt(0).toLowerCase()) {
  1091. case 'h':
  1092. return ml === 1 ? '(\\d?\\d)' : '(\\d{' + ml + '})';
  1093. case 'm':
  1094. return ml === 1 ? '(\\d?\\d)' : '(\\d{' + ml + '})';
  1095. case 's':
  1096. return ml === 1 ? '(\\d?\\d)' : '(\\d{' + ml + '})';
  1097. case 'l':
  1098. return '(\\d?\\d?\\d)';
  1099. case 'c':
  1100. return '(\\d?\\d?\\d)';
  1101. case 'z':
  1102. return '(z|[-+]\\d\\d:?\\d\\d|\\S+)?';
  1103. case 't':
  1104. return getPatternAmpm(o.amNames, o.pmNames);
  1105. default: // literal escaped in quotes
  1106. return '(' + match.replace(/\'/g, "").replace(/(\.|\$|\^|\\|\/|\(|\)|\[|\]|\?|\+|\*)/g, function (m) { return "\\" + m; }) + ')?';
  1107. }
  1108. })
  1109. .replace(/\s/g, '\\s?') +
  1110. o.timeSuffix + '$',
  1111. order = getFormatPositions(f),
  1112. ampm = '',
  1113. treg;
  1114. treg = s.match(new RegExp(regstr, 'i'));
  1115. var resTime = {
  1116. hour: 0,
  1117. minute: 0,
  1118. second: 0,
  1119. millisec: 0,
  1120. microsec: 0
  1121. };
  1122. if (treg) {
  1123. if (order.t !== -1) {
  1124. if (treg[order.t] === undefined || treg[order.t].length === 0) {
  1125. ampm = '';
  1126. resTime.ampm = '';
  1127. } else {
  1128. ampm = $.inArray(treg[order.t].toUpperCase(), o.amNames) !== -1 ? 'AM' : 'PM';
  1129. resTime.ampm = o[ampm === 'AM' ? 'amNames' : 'pmNames'][0];
  1130. }
  1131. }
  1132. if (order.h !== -1) {
  1133. if (ampm === 'AM' && treg[order.h] === '12') {
  1134. resTime.hour = 0; // 12am = 0 hour
  1135. } else {
  1136. if (ampm === 'PM' && treg[order.h] !== '12') {
  1137. resTime.hour = parseInt(treg[order.h], 10) + 12; // 12pm = 12 hour, any other pm = hour + 12
  1138. } else {
  1139. resTime.hour = Number(treg[order.h]);
  1140. }
  1141. }
  1142. }
  1143. if (order.m !== -1) {
  1144. resTime.minute = Number(treg[order.m]);
  1145. }
  1146. if (order.s !== -1) {
  1147. resTime.second = Number(treg[order.s]);
  1148. }
  1149. if (order.l !== -1) {
  1150. resTime.millisec = Number(treg[order.l]);
  1151. }
  1152. if (order.c !== -1) {
  1153. resTime.microsec = Number(treg[order.c]);
  1154. }
  1155. if (order.z !== -1 && treg[order.z] !== undefined) {
  1156. resTime.timezone = $.timepicker.timezoneOffsetNumber(treg[order.z]);
  1157. }
  1158. return resTime;
  1159. }
  1160. return false;
  1161. };// end strictParse
  1162. // First try JS Date, if that fails, use strictParse
  1163. var looseParse = function (f, s, o) {
  1164. try {
  1165. var d = new Date('2012-01-01 ' + s);
  1166. if (isNaN(d.getTime())) {
  1167. d = new Date('2012-01-01T' + s);
  1168. if (isNaN(d.getTime())) {
  1169. d = new Date('01/01/2012 ' + s);
  1170. if (isNaN(d.getTime())) {
  1171. throw "Unable to parse time with native Date: " + s;
  1172. }
  1173. }
  1174. }
  1175. return {
  1176. hour: d.getHours(),
  1177. minute: d.getMinutes(),
  1178. second: d.getSeconds(),
  1179. millisec: d.getMilliseconds(),
  1180. microsec: d.getMicroseconds(),
  1181. timezone: d.getTimezoneOffset() * -1
  1182. };
  1183. }
  1184. catch (err) {
  1185. try {
  1186. return strictParse(f, s, o);
  1187. }
  1188. catch (err2) {
  1189. $.timepicker.log("Unable to parse \ntimeString: " + s + "\ntimeFormat: " + f);
  1190. }
  1191. }
  1192. return false;
  1193. }; // end looseParse
  1194. if (typeof o.parse === "function") {
  1195. return o.parse(timeFormat, timeString, o);
  1196. }
  1197. if (o.parse === 'loose') {
  1198. return looseParse(timeFormat, timeString, o);
  1199. }
  1200. return strictParse(timeFormat, timeString, o);
  1201. };
  1202. /**
  1203. * Public utility to format the time
  1204. * @param {string} format format of the time
  1205. * @param {Object} time Object not a Date for timezones
  1206. * @param {Object} [options] essentially the regional[].. amNames, pmNames, ampm
  1207. * @returns {string} the formatted time
  1208. */
  1209. $.datepicker.formatTime = function (format, time, options) {
  1210. options = options || {};
  1211. options = $.extend({}, $.timepicker._defaults, options);
  1212. time = $.extend({
  1213. hour: 0,
  1214. minute: 0,
  1215. second: 0,
  1216. millisec: 0,
  1217. microsec: 0,
  1218. timezone: null
  1219. }, time);
  1220. var tmptime = format,
  1221. ampmName = options.amNames[0],
  1222. hour = parseInt(time.hour, 10);
  1223. if (hour > 11) {
  1224. ampmName = options.pmNames[0];
  1225. }
  1226. tmptime = tmptime.replace(/(?:HH?|hh?|mm?|ss?|[tT]{1,2}|[zZ]|[lc]|'.*?')/g, function (match) {
  1227. switch (match) {
  1228. case 'HH':
  1229. return ('0' + hour).slice(-2);
  1230. case 'H':
  1231. return hour;
  1232. case 'hh':
  1233. return ('0' + convert24to12(hour)).slice(-2);
  1234. case 'h':
  1235. return convert24to12(hour);
  1236. case 'mm':
  1237. return ('0' + time.minute).slice(-2);
  1238. case 'm':
  1239. return time.minute;
  1240. case 'ss':
  1241. return ('0' + time.second).slice(-2);
  1242. case 's':
  1243. return time.second;
  1244. case 'l':
  1245. return ('00' + time.millisec).slice(-3);
  1246. case 'c':
  1247. return ('00' + time.microsec).slice(-3);
  1248. case 'z':
  1249. return $.timepicker.timezoneOffsetString(time.timezone === null ? options.timezone : time.timezone, false);
  1250. case 'Z':
  1251. return $.timepicker.timezoneOffsetString(time.timezone === null ? options.timezone : time.timezone, true);
  1252. case 'T':
  1253. return ampmName.charAt(0).toUpperCase();
  1254. case 'TT':
  1255. return ampmName.toUpperCase();
  1256. case 't':
  1257. return ampmName.charAt(0).toLowerCase();
  1258. case 'tt':
  1259. return ampmName.toLowerCase();
  1260. default:
  1261. return match.replace(/'/g, "");
  1262. }
  1263. });
  1264. return tmptime;
  1265. };
  1266. /*
  1267. * the bad hack :/ override datepicker so it doesn't close on select
  1268. // inspired: http://stackoverflow.com/questions/1252512/jquery-datepicker-prevent-closing-picker-when-clicking-a-date/1762378#1762378
  1269. */
  1270. $.datepicker._base_selectDate = $.datepicker._selectDate;
  1271. $.datepicker._selectDate = function (id, dateStr) {
  1272. var inst = this._getInst($(id)[0]),
  1273. tp_inst = this._get(inst, 'timepicker');
  1274. if (tp_inst && inst.settings.showTimepicker) {
  1275. tp_inst._limitMinMaxDateTime(inst, true);
  1276. inst.inline = inst.stay_open = true;
  1277. //This way the onSelect handler called from calendarpicker get the full dateTime
  1278. this._base_selectDate(id, dateStr);
  1279. inst.inline = inst.stay_open = false;
  1280. this._notifyChange(inst);
  1281. this._updateDatepicker(inst);
  1282. } else {
  1283. this._base_selectDate(id, dateStr);
  1284. }
  1285. };
  1286. /*
  1287. * second bad hack :/ override datepicker so it triggers an event when changing the input field
  1288. * and does not redraw the datepicker on every selectDate event
  1289. */
  1290. $.datepicker._base_updateDatepicker = $.datepicker._updateDatepicker;
  1291. $.datepicker._updateDatepicker = function (inst) {
  1292. // don't popup the datepicker if there is another instance already opened
  1293. var input = inst.input[0];
  1294. if ($.datepicker._curInst && $.datepicker._curInst !== inst && $.datepicker._datepickerShowing && $.datepicker._lastInput !== input) {
  1295. return;
  1296. }
  1297. if (typeof(inst.stay_open) !== 'boolean' || inst.stay_open === false) {
  1298. this._base_updateDatepicker(inst);
  1299. // Reload the time control when changing something in the input text field.
  1300. var tp_inst = this._get(inst, 'timepicker');
  1301. if (tp_inst) {
  1302. tp_inst._addTimePicker(inst);
  1303. }
  1304. }
  1305. };
  1306. /*
  1307. * third bad hack :/ override datepicker so it allows spaces and colon in the input field
  1308. */
  1309. $.datepicker._base_doKeyPress = $.datepicker._doKeyPress;
  1310. $.datepicker._doKeyPress = function (event) {
  1311. var inst = $.datepicker._getInst(event.target),
  1312. tp_inst = $.datepicker._get(inst, 'timepicker');
  1313. if (tp_inst) {
  1314. if ($.datepicker._get(inst, 'constrainInput')) {
  1315. var ampm = tp_inst.support.ampm,
  1316. tz = tp_inst._defaults.showTimezone !== null ? tp_inst._defaults.showTimezone : tp_inst.support.timezone,
  1317. dateChars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat')),
  1318. datetimeChars = tp_inst._defaults.timeFormat.toString()
  1319. .replace(/[hms]/g, '')
  1320. .replace(/TT/g, ampm ? 'APM' : '')
  1321. .replace(/Tt/g, ampm ? 'AaPpMm' : '')
  1322. .replace(/tT/g, ampm ? 'AaPpMm' : '')
  1323. .replace(/T/g, ampm ? 'AP' : '')
  1324. .replace(/tt/g, ampm ? 'apm' : '')
  1325. .replace(/t/g, ampm ? 'ap' : '') +
  1326. " " + tp_inst._defaults.separator +
  1327. tp_inst._defaults.timeSuffix +
  1328. (tz ? tp_inst._defaults.timezoneList.join('') : '') +
  1329. (tp_inst._defaults.amNames.join('')) + (tp_inst._defaults.pmNames.join('')) +
  1330. dateChars,
  1331. chr = String.fromCharCode(event.charCode === undefined ? event.keyCode : event.charCode);
  1332. return event.ctrlKey || (chr < ' ' || !dateChars || datetimeChars.indexOf(chr) > -1);
  1333. }
  1334. }
  1335. return $.datepicker._base_doKeyPress(event);
  1336. };
  1337. /*
  1338. * Fourth bad hack :/ override _updateAlternate function used in inline mode to init altField
  1339. * Update any alternate field to synchronise with the main field.
  1340. */
  1341. $.datepicker._base_updateAlternate = $.datepicker._updateAlternate;
  1342. $.datepicker._updateAlternate = function (inst) {
  1343. var tp_inst = this._get(inst, 'timepicker');
  1344. if (tp_inst) {
  1345. var altField = tp_inst._defaults.altField;
  1346. if (altField) { // update alternate field too
  1347. var altFormat = tp_inst._defaults.altFormat || tp_inst._defaults.dateFormat,
  1348. date = this._getDate(inst),
  1349. formatCfg = $.datepicker._getFormatConfig(inst),
  1350. altFormattedDateTime = '',
  1351. altSeparator = tp_inst._defaults.altSeparator ? tp_inst._defaults.altSeparator : tp_inst._defaults.separator,
  1352. altTimeSuffix = tp_inst._defaults.altTimeSuffix ? tp_inst._defaults.altTimeSuffix : tp_inst._defaults.timeSuffix,
  1353. altTimeFormat = tp_inst._defaults.altTimeFormat !== null ? tp_inst._defaults.altTimeFormat : tp_inst._defaults.timeFormat;
  1354. altFormattedDateTime += $.datepicker.formatTime(altTimeFormat, tp_inst, tp_inst._defaults) + altTimeSuffix;
  1355. if (!tp_inst._defaults.timeOnly && !tp_inst._defaults.altFieldTimeOnly && date !== null) {
  1356. if (tp_inst._defaults.altFormat) {
  1357. altFormattedDateTime = $.datepicker.formatDate(tp_inst._defaults.altFormat, date, formatCfg) + altSeparator + altFormattedDateTime;
  1358. }
  1359. else {
  1360. altFormattedDateTime = tp_inst.formattedDate + altSeparator + altFormattedDateTime;
  1361. }
  1362. }
  1363. $(altField).val( inst.input.val() ? altFormattedDateTime : "");
  1364. }
  1365. }
  1366. else {
  1367. $.datepicker._base_updateAlternate(inst);
  1368. }
  1369. };
  1370. /*
  1371. * Override key up event to sync manual input changes.
  1372. */
  1373. $.datepicker._base_doKeyUp = $.datepicker._doKeyUp;
  1374. $.datepicker._doKeyUp = function (event) {
  1375. var inst = $.datepicker._getInst(event.target),
  1376. tp_inst = $.datepicker._get(inst, 'timepicker');
  1377. if (tp_inst) {
  1378. if (tp_inst._defaults.timeOnly && (inst.input.val() !== inst.lastVal)) {
  1379. try {
  1380. $.datepicker._updateDatepicker(inst);
  1381. } catch (err) {
  1382. $.timepicker.log(err);
  1383. }
  1384. }
  1385. }
  1386. return $.datepicker._base_doKeyUp(event);
  1387. };
  1388. /*
  1389. * override "Today" button to also grab the time.
  1390. */
  1391. $.datepicker._base_gotoToday = $.datepicker._gotoToday;
  1392. $.datepicker._gotoToday = function (id) {
  1393. var inst = this._getInst($(id)[0]),
  1394. $dp = inst.dpDiv;
  1395. this._base_gotoToday(id);
  1396. var tp_inst = this._get(inst, 'timepicker');
  1397. selectLocalTimezone(tp_inst);
  1398. var now = new Date();
  1399. this._setTime(inst, now);
  1400. $('.ui-datepicker-today', $dp).click();
  1401. };
  1402. /*
  1403. * Disable & enable the Time in the datetimepicker
  1404. */
  1405. $.datepicker._disableTimepickerDatepicker = function (target) {
  1406. var inst = this._getInst(target);
  1407. if (!inst) {
  1408. return;
  1409. }
  1410. var tp_inst = this._get(inst, 'timepicker');
  1411. $(target).datepicker('getDate'); // Init selected[Year|Month|Day]
  1412. if (tp_inst) {
  1413. inst.settings.showTimepicker = false;
  1414. tp_inst._defaults.showTimepicker = false;
  1415. tp_inst._updateDateTime(inst);
  1416. }
  1417. };
  1418. $.datepicker._enableTimepickerDatepicker = function (target) {
  1419. var inst = this._getInst(target);
  1420. if (!inst) {
  1421. return;
  1422. }
  1423. var tp_inst = this._get(inst, 'timepicker');
  1424. $(target).datepicker('getDate'); // Init selected[Year|Month|Day]
  1425. if (tp_inst) {
  1426. inst.settings.showTimepicker = true;
  1427. tp_inst._defaults.showTimepicker = true;
  1428. tp_inst._addTimePicker(inst); // Could be disabled on page load
  1429. tp_inst._updateDateTime(inst);
  1430. }
  1431. };
  1432. /*
  1433. * Create our own set time function
  1434. */
  1435. $.datepicker._setTime = function (inst, date) {
  1436. var tp_inst = this._get(inst, 'timepicker');
  1437. if (tp_inst) {
  1438. var defaults = tp_inst._defaults;
  1439. // calling _setTime with no date sets time to defaults
  1440. tp_inst.hour = date ? date.getHours() : defaults.hour;
  1441. tp_inst.minute = date ? date.getMinutes() : defaults.minute;
  1442. tp_inst.second = date ? date.getSeconds() : defaults.second;
  1443. tp_inst.millisec = date ? date.getMilliseconds() : defaults.millisec;
  1444. tp_inst.microsec = date ? date.getMicroseconds() : defaults.microsec;
  1445. //check if within min/max times..
  1446. tp_inst._limitMinMaxDateTime(inst, true);
  1447. tp_inst._onTimeChange();
  1448. tp_inst._updateDateTime(inst);
  1449. }
  1450. };
  1451. /*
  1452. * Create new public method to set only time, callable as $().datepicker('setTime', date)
  1453. */
  1454. $.datepicker._setTimeDatepicker = function (target, date, withDate) {
  1455. var inst = this._getInst(target);
  1456. if (!inst) {
  1457. return;
  1458. }
  1459. var tp_inst = this._get(inst, 'timepicker');
  1460. if (tp_inst) {
  1461. this._setDateFromField(inst);
  1462. var tp_date;
  1463. if (date) {
  1464. if (typeof date === "string") {
  1465. tp_inst._parseTime(date, withDate);
  1466. tp_date = new Date();
  1467. tp_date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec);
  1468. tp_date.setMicroseconds(tp_inst.microsec);
  1469. } else {
  1470. tp_date = new Date(date.getTime());
  1471. tp_date.setMicroseconds(date.getMicroseconds());
  1472. }
  1473. if (tp_date.toString() === 'Invalid Date') {
  1474. tp_date = undefined;
  1475. }
  1476. this._setTime(inst, tp_date);
  1477. }
  1478. }
  1479. };
  1480. /*
  1481. * override setDate() to allow setting time too within Date object
  1482. */
  1483. $.datepicker._base_setDateDatepicker = $.datepicker._setDateDatepicker;
  1484. $.datepicker._setDateDatepicker = function (target, _date) {
  1485. var inst = this._getInst(target);
  1486. var date = _date;
  1487. if (!inst) {
  1488. return;
  1489. }
  1490. if (typeof(_date) === 'string') {
  1491. date = new Date(_date);
  1492. if (!date.getTime()) {
  1493. this._base_setDateDatepicker.apply(this, arguments);
  1494. date = $(target).datepicker('getDate');
  1495. }
  1496. }
  1497. var tp_inst = this._get(inst, 'timepicker');
  1498. var tp_date;
  1499. if (date instanceof Date) {
  1500. tp_date = new Date(date.getTime());
  1501. tp_date.setMicroseconds(date.getMicroseconds());
  1502. } else {
  1503. tp_date = date;
  1504. }
  1505. // This is important if you are using the timezone option, javascript's Date
  1506. // object will only return the timezone offset for the current locale, so we
  1507. // adjust it accordingly. If not using timezone option this won't matter..
  1508. // If a timezone is different in tp, keep the timezone as is
  1509. if (tp_inst && tp_date) {
  1510. // look out for DST if tz wasn't specified
  1511. if (!tp_inst.support.timezone && tp_inst._defaults.timezone === null) {
  1512. tp_inst.timezone = tp_date.getTimezoneOffset() * -1;
  1513. }
  1514. date = $.timepicker.timezoneAdjust(date, tp_inst.timezone);
  1515. tp_date = $.timepicker.timezoneAdjust(tp_date, tp_inst.timezone);
  1516. }
  1517. this._updateDatepicker(inst);
  1518. this._base_setDateDatepicker.apply(this, arguments);
  1519. this._setTimeDatepicker(target, tp_date, true);
  1520. };
  1521. /*
  1522. * override getDate() to allow getting time too within Date object
  1523. */
  1524. $.datepicker._base_getDateDatepicker = $.datepicker._getDateDatepicker;
  1525. $.datepicker._getDateDatepicker = function (target, noDefault) {
  1526. var inst = this._getInst(target);
  1527. if (!inst) {
  1528. return;
  1529. }
  1530. var tp_inst = this._get(inst, 'timepicker');
  1531. if (tp_inst) {
  1532. // if it hasn't yet been defined, grab from field
  1533. if (inst.lastVal === undefined) {
  1534. this._setDateFromField(inst, noDefault);
  1535. }
  1536. var date = this._getDate(inst);
  1537. if (date && tp_inst._parseTime($(target).val(), tp_inst.timeOnly)) {
  1538. date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec);
  1539. date.setMicroseconds(tp_inst.microsec);
  1540. // This is important if you are using the timezone option, javascript's Date
  1541. // object will only return the timezone offset for the current locale, so we
  1542. // adjust it accordingly. If not using timezone option this won't matter..
  1543. if (tp_inst.timezone != null) {
  1544. // look out for DST if tz wasn't specified
  1545. if (!tp_inst.support.timezone && tp_inst._defaults.timezone === null) {
  1546. tp_inst.timezone = date.getTimezoneOffset() * -1;
  1547. }
  1548. date = $.timepicker.timezoneAdjust(date, tp_inst.timezone);
  1549. }
  1550. }
  1551. return date;
  1552. }
  1553. return this._base_getDateDatepicker(target, noDefault);
  1554. };
  1555. /*
  1556. * override parseDate() because UI 1.8.14 throws an error about "Extra characters"
  1557. * An option in datapicker to ignore extra format characters would be nicer.
  1558. */
  1559. $.datepicker._base_parseDate = $.datepicker.parseDate;
  1560. $.datepicker.parseDate = function (format, value, settings) {
  1561. var date;
  1562. try {
  1563. date = this._base_parseDate(format, value, settings);
  1564. } catch (err) {
  1565. // Hack! The error message ends with a colon, a space, and
  1566. // the "extra" characters. We rely on that instead of
  1567. // attempting to perfectly reproduce the parsing algorithm.
  1568. if (err.indexOf(":") >= 0) {
  1569. date = this._base_parseDate(format, value.substring(0, value.length - (err.length - err.indexOf(':') - 2)), settings);
  1570. $.timepicker.log("Error parsing the date string: " + err + "\ndate string = " + value + "\ndate format = " + format);
  1571. } else {
  1572. throw err;
  1573. }
  1574. }
  1575. return date;
  1576. };
  1577. /*
  1578. * override formatDate to set date with time to the input
  1579. */
  1580. $.datepicker._base_formatDate = $.datepicker._formatDate;
  1581. $.datepicker._formatDate = function (inst, day, month, year) {
  1582. var tp_inst = this._get(inst, 'timepicker');
  1583. if (tp_inst) {
  1584. tp_inst._updateDateTime(inst);
  1585. return tp_inst.$input.val();
  1586. }
  1587. return this._base_formatDate(inst);
  1588. };
  1589. /*
  1590. * override options setter to add time to maxDate(Time) and minDate(Time). MaxDate
  1591. */
  1592. $.datepicker._base_optionDatepicker = $.datepicker._optionDatepicker;
  1593. $.datepicker._optionDatepicker = function (target, name, value) {
  1594. var inst = this._getInst(target),
  1595. name_clone;
  1596. if (!inst) {
  1597. return null;
  1598. }
  1599. var tp_inst = this._get(inst, 'timepicker');
  1600. if (tp_inst) {
  1601. var min = null,
  1602. max = null,
  1603. onselect = null,
  1604. overrides = tp_inst._defaults.evnts,
  1605. fns = {},
  1606. prop;
  1607. if (typeof name === 'string') { // if min/max was set with the string
  1608. if (name === 'minDate' || name === 'minDateTime') {
  1609. min = value;
  1610. } else if (name === 'maxDate' || name === 'maxDateTime') {
  1611. max = value;
  1612. } else if (name === 'onSelect') {
  1613. onselect = value;
  1614. } else if (overrides.hasOwnProperty(name)) {
  1615. if (typeof (value) === 'undefined') {
  1616. return overrides[name];
  1617. }
  1618. fns[name] = value;
  1619. name_clone = {}; //empty results in exiting function after overrides updated
  1620. }
  1621. } else if (typeof name === 'object') { //if min/max was set with the JSON
  1622. if (name.minDate) {
  1623. min = name.minDate;
  1624. } else if (name.minDateTime) {
  1625. min = name.minDateTime;
  1626. } else if (name.maxDate) {
  1627. max = name.maxDate;
  1628. } else if (name.maxDateTime) {
  1629. max = name.maxDateTime;
  1630. }
  1631. for (prop in overrides) {
  1632. if (overrides.hasOwnProperty(prop) && name[prop]) {
  1633. fns[prop] = name[prop];
  1634. }
  1635. }
  1636. }
  1637. for (prop in fns) {
  1638. if (fns.hasOwnProperty(prop)) {
  1639. overrides[prop] = fns[prop];
  1640. if (!name_clone) { name_clone = $.extend({}, name); }
  1641. delete name_clone[prop];
  1642. }
  1643. }
  1644. if (name_clone && isEmptyObject(name_clone)) { return; }
  1645. if (min) { //if min was set
  1646. if (min === 0) {
  1647. min = new Date();
  1648. } else {
  1649. min = new Date(min);
  1650. }
  1651. tp_inst._defaults.minDate = min;
  1652. tp_inst._defaults.minDateTime = min;
  1653. } else if (max) { //if max was set
  1654. if (max === 0) {
  1655. max = new Date();
  1656. } else {
  1657. max = new Date(max);
  1658. }
  1659. tp_inst._defaults.maxDate = max;
  1660. tp_inst._defaults.maxDateTime = max;
  1661. } else if (onselect) {
  1662. tp_inst._defaults.onSelect = onselect;
  1663. }
  1664. }
  1665. if (value === undefined) {
  1666. return this._base_optionDatepicker.call($.datepicker, target, name);
  1667. }
  1668. return this._base_optionDatepicker.call($.datepicker, target, name_clone || name, value);
  1669. };
  1670. /*
  1671. * jQuery isEmptyObject does not check hasOwnProperty - if someone has added to the object prototype,
  1672. * it will return false for all objects
  1673. */
  1674. var isEmptyObject = function (obj) {
  1675. var prop;
  1676. for (prop in obj) {
  1677. if (obj.hasOwnProperty(prop)) {
  1678. return false;
  1679. }
  1680. }
  1681. return true;
  1682. };
  1683. /*
  1684. * jQuery extend now ignores nulls!
  1685. */
  1686. var extendRemove = function (target, props) {
  1687. $.extend(target, props);
  1688. for (var name in props) {
  1689. if (props[name] === null || props[name] === undefined) {
  1690. target[name] = props[name];
  1691. }
  1692. }
  1693. return target;
  1694. };
  1695. /*
  1696. * Determine by the time format which units are supported
  1697. * Returns an object of booleans for each unit
  1698. */
  1699. var detectSupport = function (timeFormat) {
  1700. var tf = timeFormat.replace(/'.*?'/g, '').toLowerCase(), // removes literals
  1701. isIn = function (f, t) { // does the format contain the token?
  1702. return f.indexOf(t) !== -1 ? true : false;
  1703. };
  1704. return {
  1705. hour: isIn(tf, 'h'),
  1706. minute: isIn(tf, 'm'),
  1707. second: isIn(tf, 's'),
  1708. millisec: isIn(tf, 'l'),
  1709. microsec: isIn(tf, 'c'),
  1710. timezone: isIn(tf, 'z'),
  1711. ampm: isIn(tf, 't') && isIn(timeFormat, 'h'),
  1712. iso8601: isIn(timeFormat, 'Z')
  1713. };
  1714. };
  1715. /*
  1716. * Converts 24 hour format into 12 hour
  1717. * Returns 12 hour without leading 0
  1718. */
  1719. var convert24to12 = function (hour) {
  1720. hour %= 12;
  1721. if (hour === 0) {
  1722. hour = 12;
  1723. }
  1724. return String(hour);
  1725. };
  1726. var computeEffectiveSetting = function (settings, property) {
  1727. return settings && settings[property] ? settings[property] : $.timepicker._defaults[property];
  1728. };
  1729. /*
  1730. * Splits datetime string into date and time substrings.
  1731. * Throws exception when date can't be parsed
  1732. * Returns {dateString: dateString, timeString: timeString}
  1733. */
  1734. var splitDateTime = function (dateTimeString, timeSettings) {
  1735. // The idea is to get the number separator occurrences in datetime and the time format requested (since time has
  1736. // fewer unknowns, mostly numbers and am/pm). We will use the time pattern to split.
  1737. var separator = computeEffectiveSetting(timeSettings, 'separator'),
  1738. format = computeEffectiveSetting(timeSettings, 'timeFormat'),
  1739. timeParts = format.split(separator), // how many occurrences of separator may be in our format?
  1740. timePartsLen = timeParts.length,
  1741. allParts = dateTimeString.split(separator),
  1742. allPartsLen = allParts.length;
  1743. if (allPartsLen > 1) {
  1744. return {
  1745. dateString: allParts.splice(0, allPartsLen - timePartsLen).join(separator),
  1746. timeString: allParts.splice(0, timePartsLen).join(separator)
  1747. };
  1748. }
  1749. return {
  1750. dateString: dateTimeString,
  1751. timeString: ''
  1752. };
  1753. };
  1754. /*
  1755. * Internal function to parse datetime interval
  1756. * Returns: {date: Date, timeObj: Object}, where
  1757. * date - parsed date without time (type Date)
  1758. * timeObj = {hour: , minute: , second: , millisec: , microsec: } - parsed time. Optional
  1759. */
  1760. var parseDateTimeInternal = function (dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings) {
  1761. var date,
  1762. parts,
  1763. parsedTime;
  1764. parts = splitDateTime(dateTimeString, timeSettings);
  1765. date = $.datepicker._base_parseDate(dateFormat, parts.dateString, dateSettings);
  1766. if (parts.timeString === '') {
  1767. return {
  1768. date: date
  1769. };
  1770. }
  1771. parsedTime = $.datepicker.parseTime(timeFormat, parts.timeString, timeSettings);
  1772. if (!parsedTime) {
  1773. throw 'Wrong time format';
  1774. }
  1775. return {
  1776. date: date,
  1777. timeObj: parsedTime
  1778. };
  1779. };
  1780. /*
  1781. * Internal function to set timezone_select to the local timezone
  1782. */
  1783. var selectLocalTimezone = function (tp_inst, date) {
  1784. if (tp_inst && tp_inst.timezone_select) {
  1785. var now = date || new Date();
  1786. tp_inst.timezone_select.val(-now.getTimezoneOffset());
  1787. }
  1788. };
  1789. /*
  1790. * Create a Singleton Instance
  1791. */
  1792. $.timepicker = new Timepicker();
  1793. /**
  1794. * Get the timezone offset as string from a date object (eg '+0530' for UTC+5.5)
  1795. * @param {number} tzMinutes if not a number, less than -720 (-1200), or greater than 840 (+1400) this value is returned
  1796. * @param {boolean} iso8601 if true formats in accordance to iso8601 "+12:45"
  1797. * @return {string}
  1798. */
  1799. $.timepicker.timezoneOffsetString = function (tzMinutes, iso8601) {
  1800. if (isNaN(tzMinutes) || tzMinutes > 840 || tzMinutes < -720) {
  1801. return tzMinutes;
  1802. }
  1803. var off = tzMinutes,
  1804. minutes = off % 60,
  1805. hours = (off - minutes) / 60,
  1806. iso = iso8601 ? ':' : '',
  1807. tz = (off >= 0 ? '+' : '-') + ('0' + Math.abs(hours)).slice(-2) + iso + ('0' + Math.abs(minutes)).slice(-2);
  1808. if (tz === '+00:00') {
  1809. return 'Z';
  1810. }
  1811. return tz;
  1812. };
  1813. /**
  1814. * Get the number in minutes that represents a timezone string
  1815. * @param {string} tzString formatted like "+0500", "-1245", "Z"
  1816. * @return {number} the offset minutes or the original string if it doesn't match expectations
  1817. */
  1818. $.timepicker.timezoneOffsetNumber = function (tzString) {
  1819. var normalized = tzString.toString().replace(':', ''); // excuse any iso8601, end up with "+1245"
  1820. if (normalized.toUpperCase() === 'Z') { // if iso8601 with Z, its 0 minute offset
  1821. return 0;
  1822. }
  1823. if (!/^(\-|\+)\d{4}$/.test(normalized)) { // possibly a user defined tz, so just give it back
  1824. return tzString;
  1825. }
  1826. return ((normalized.substr(0, 1) === '-' ? -1 : 1) * // plus or minus
  1827. ((parseInt(normalized.substr(1, 2), 10) * 60) + // hours (converted to minutes)
  1828. parseInt(normalized.substr(3, 2), 10))); // minutes
  1829. };
  1830. /**
  1831. * No way to set timezone in js Date, so we must adjust the minutes to compensate. (think setDate, getDate)
  1832. * @param {Date} date
  1833. * @param {string} toTimezone formatted like "+0500", "-1245"
  1834. * @return {Date}
  1835. */
  1836. $.timepicker.timezoneAdjust = function (date, toTimezone) {
  1837. var toTz = $.timepicker.timezoneOffsetNumber(toTimezone);
  1838. if (!isNaN(toTz)) {
  1839. date.setMinutes(date.getMinutes() + -date.getTimezoneOffset() - toTz);
  1840. }
  1841. return date;
  1842. };
  1843. /**
  1844. * Calls `timepicker()` on the `startTime` and `endTime` elements, and configures them to
  1845. * enforce date range limits.
  1846. * n.b. The input value must be correctly formatted (reformatting is not supported)
  1847. * @param {Element} startTime
  1848. * @param {Element} endTime
  1849. * @param {Object} options Options for the timepicker() call
  1850. * @return {jQuery}
  1851. */
  1852. $.timepicker.timeRange = function (startTime, endTime, options) {
  1853. return $.timepicker.handleRange('timepicker', startTime, endTime, options);
  1854. };
  1855. /**
  1856. * Calls `datetimepicker` on the `startTime` and `endTime` elements, and configures them to
  1857. * enforce date range limits.
  1858. * @param {Element} startTime
  1859. * @param {Element} endTime
  1860. * @param {Object} options Options for the `timepicker()` call. Also supports `reformat`,
  1861. * a boolean value that can be used to reformat the input values to the `dateFormat`.
  1862. * @param {string} method Can be used to specify the type of picker to be added
  1863. * @return {jQuery}
  1864. */
  1865. $.timepicker.datetimeRange = function (startTime, endTime, options) {
  1866. $.timepicker.handleRange('datetimepicker', startTime, endTime, options);
  1867. };
  1868. /**
  1869. * Calls `datepicker` on the `startTime` and `endTime` elements, and configures them to
  1870. * enforce date range limits.
  1871. * @param {Element} startTime
  1872. * @param {Element} endTime
  1873. * @param {Object} options Options for the `timepicker()` call. Also supports `reformat`,
  1874. * a boolean value that can be used to reformat the input values to the `dateFormat`.
  1875. * @return {jQuery}
  1876. */
  1877. $.timepicker.dateRange = function (startTime, endTime, options) {
  1878. $.timepicker.handleRange('datepicker', startTime, endTime, options);
  1879. };
  1880. /**
  1881. * Calls `method` on the `startTime` and `endTime` elements, and configures them to
  1882. * enforce date range limits.
  1883. * @param {string} method Can be used to specify the type of picker to be added
  1884. * @param {Element} startTime
  1885. * @param {Element} endTime
  1886. * @param {Object} options Options for the `timepicker()` call. Also supports `reformat`,
  1887. * a boolean value that can be used to reformat the input values to the `dateFormat`.
  1888. * @return {jQuery}
  1889. */
  1890. $.timepicker.handleRange = function (method, startTime, endTime, options) {
  1891. options = $.extend({}, {
  1892. minInterval: 0, // min allowed interval in milliseconds
  1893. maxInterval: 0, // max allowed interval in milliseconds
  1894. start: {}, // options for start picker
  1895. end: {} // options for end picker
  1896. }, options);
  1897. // for the mean time this fixes an issue with calling getDate with timepicker()
  1898. var timeOnly = false;
  1899. if(method === 'timepicker'){
  1900. timeOnly = true;
  1901. method = 'datetimepicker';
  1902. }
  1903. function checkDates(changed, other) {
  1904. var startdt = startTime[method]('getDate'),
  1905. enddt = endTime[method]('getDate'),
  1906. changeddt = changed[method]('getDate');
  1907. if (startdt !== null) {
  1908. var minDate = new Date(startdt.getTime()),
  1909. maxDate = new Date(startdt.getTime());
  1910. minDate.setMilliseconds(minDate.getMilliseconds() + options.minInterval);
  1911. maxDate.setMilliseconds(maxDate.getMilliseconds() + options.maxInterval);
  1912. if (options.minInterval > 0 && minDate > enddt) { // minInterval check
  1913. endTime[method]('setDate', minDate);
  1914. }
  1915. else if (options.maxInterval > 0 && maxDate < enddt) { // max interval check
  1916. endTime[method]('setDate', maxDate);
  1917. }
  1918. else if (startdt > enddt) {
  1919. other[method]('setDate', changeddt);
  1920. }
  1921. }
  1922. }
  1923. function selected(changed, other, option) {
  1924. if (!changed.val()) {
  1925. return;
  1926. }
  1927. var date = changed[method].call(changed, 'getDate');
  1928. if (date !== null && options.minInterval > 0) {
  1929. if (option === 'minDate') {
  1930. date.setMilliseconds(date.getMilliseconds() + options.minInterval);
  1931. }
  1932. if (option === 'maxDate') {
  1933. date.setMilliseconds(date.getMilliseconds() - options.minInterval);
  1934. }
  1935. }
  1936. if (date.getTime) {
  1937. other[method].call(other, 'option', option, date);
  1938. }
  1939. }
  1940. $.fn[method].call(startTime, $.extend({
  1941. timeOnly: timeOnly,
  1942. onClose: function (dateText, inst) {
  1943. checkDates($(this), endTime);
  1944. },
  1945. onSelect: function (selectedDateTime) {
  1946. selected($(this), endTime, 'minDate');
  1947. }
  1948. }, options, options.start));
  1949. $.fn[method].call(endTime, $.extend({
  1950. timeOnly: timeOnly,
  1951. onClose: function (dateText, inst) {
  1952. checkDates($(this), startTime);
  1953. },
  1954. onSelect: function (selectedDateTime) {
  1955. selected($(this), startTime, 'maxDate');
  1956. }
  1957. }, options, options.end));
  1958. checkDates(startTime, endTime);
  1959. selected(startTime, endTime, 'minDate');
  1960. selected(endTime, startTime, 'maxDate');
  1961. return $([startTime.get(0), endTime.get(0)]);
  1962. };
  1963. /**
  1964. * Log error or data to the console during error or debugging
  1965. * @param {Object} err pass any type object to log to the console during error or debugging
  1966. * @return {void}
  1967. */
  1968. $.timepicker.log = function (err) {
  1969. if (window.console) {
  1970. window.console.log(err);
  1971. }
  1972. };
  1973. /*
  1974. * Add util object to allow access to private methods for testability.
  1975. */
  1976. $.timepicker._util = {
  1977. _extendRemove: extendRemove,
  1978. _isEmptyObject: isEmptyObject,
  1979. _convert24to12: convert24to12,
  1980. _detectSupport: detectSupport,
  1981. _selectLocalTimezone: selectLocalTimezone,
  1982. _computeEffectiveSetting: computeEffectiveSetting,
  1983. _splitDateTime: splitDateTime,
  1984. _parseDateTimeInternal: parseDateTimeInternal
  1985. };
  1986. /*
  1987. * Microsecond support
  1988. */
  1989. if (!Date.prototype.getMicroseconds) {
  1990. Date.prototype.microseconds = 0;
  1991. Date.prototype.getMicroseconds = function () { return this.microseconds; };
  1992. Date.prototype.setMicroseconds = function (m) {
  1993. this.setMilliseconds(this.getMilliseconds() + Math.floor(m / 1000));
  1994. this.microseconds = m % 1000;
  1995. return this;
  1996. };
  1997. }
  1998. /*
  1999. * Keep up with the version
  2000. */
  2001. $.timepicker.version = "1.4.5";
  2002. })(jQuery);