datetimepicker.js 82 KB

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