WME Utils - HoursParser

Parses a text string into hours, for use in Waze Map Editor scripts

目前为 2018-01-15 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/37486/243581/WME%20Utils%20-%20HoursParser.js

  1. // ==UserScript==
  2. // @name WME Utils - HoursParser
  3. // @version 2018.01.15.003
  4. // ==/UserScript==
  5.  
  6. class HoursParser {
  7. constructor() {
  8. this.DAYS_OF_THE_WEEK = {
  9. SS: ['saturdays', 'saturday', 'satur', 'sat', 'sa'],
  10. UU: ['sundays', 'sunday', 'sun', 'su'],
  11. MM: ['mondays', 'monday', 'mondy', 'mon', 'mo'],
  12. TT: ['tuesdays', 'tuesday', 'tues', 'tue', 'tu'],
  13. WW: ['wednesdays', 'wednesday', 'weds', 'wed', 'we'],
  14. RR: ['thursdays', 'thursday', 'thurs', 'thur', 'thu', 'th'],
  15. FF: ['fridays', 'friday', 'fri', 'fr']
  16. };
  17. this.MONTHS_OF_THE_YEAR = {
  18. JAN: ['january', 'jan'],
  19. FEB: ['february', 'febr', 'feb'],
  20. MAR: ['march', 'mar'],
  21. APR: ['april', 'apr'],
  22. MAY: ['may', 'may'],
  23. JUN: ['june', 'jun'],
  24. JUL: ['july', 'jul'],
  25. AUG: ['august', 'aug'],
  26. SEP: ['september', 'sept', 'sep'],
  27. OCT: ['october', 'oct'],
  28. NOV: ['november', 'nov'],
  29. DEC: ['december', 'dec']
  30. };
  31. this.DAY_CODE_VECTOR = ['MM','TT','WW','RR','FF','SS','UU','MM','TT','WW','RR','FF','SS','UU','MM','TT','WW','RR','FF'];
  32. this.THRU_WORDS = ['through','thru','to','until','till','til','-','~'];
  33. }
  34.  
  35. parseHours(inputHours, locale) {
  36. let returnVal = {
  37. hours: [],
  38. parseError: false,
  39. overlappingHours: false,
  40. sameOpenAndCloseTimes: false
  41. };
  42.  
  43. let tfHourTemp, tfDaysTemp, newDayCodeVec = [];
  44. let tempRegex, twix, tsix;
  45. let inputHoursParse = inputHours.toLowerCase().trim();
  46. if (inputHoursParse.length === 0 || inputHoursParse === ',') {
  47. return returnVal;
  48. }
  49. let today = new Date();
  50. let tomorrow = new Date();
  51. tomorrow.setDate(tomorrow.getDate() + 1);
  52. inputHoursParse = inputHoursParse.replace(/\btoday\b/g, today.toLocaleDateString(locale, {weekday:'short'}).toLowerCase())
  53. .replace(/\btomorrow\b/g, tomorrow.toLocaleDateString(locale, {weekday:'short'}).toLowerCase())
  54. .replace(/\u2013|\u2014/g, "-") // long dash replacing
  55. .replace(/[^a-z0-9\:\-\. ~]/g, ' ') // replace unnecessary characters with spaces
  56. .replace(/\:{2,}/g, ':') // remove extra colons
  57. .replace(/closed|not open/g, '99:99-99:99') // parse 'closed'
  58. .replace(/by appointment( only)?/g, '99:99-99:99') // parse 'appointment only'
  59. .replace(/weekdays/g, 'mon-fri').replace(/weekends/g, 'sat-sun') // convert weekdays and weekends to days
  60. .replace(/(12(:00)?\W*)?noon/g, "12:00").replace(/(12(:00)?\W*)?mid(night|nite)/g, "00:00") // replace 'noon', 'midnight'
  61. .replace(/every\s*day|daily|(7|seven) days a week/g, "mon-sun") // replace 'seven days a week'
  62. .replace(/(open\s*)?(24|twenty\W*four)\W*h(ou)?rs?|all day/g, "00:00-00:00") // replace 'open 24 hour or similar'
  63. .replace(/(\D:)([^ ])/g, "$1 $2"); // space after colons after words
  64.  
  65. // replace thru type words with dashes
  66. this.THRU_WORDS.forEach(word => {
  67. inputHoursParse = inputHoursParse.replace( new RegExp(word, 'g'), '-');
  68. });
  69.  
  70. inputHoursParse = inputHoursParse.replace(/\-{2,}/g, "-"); // replace any duplicate dashes
  71.  
  72. // kill extra words
  73. let killWords = 'paste|here|business|operation|times|time|walk-ins|walk ins|welcome|dinner|lunch|brunch|breakfast|regular|weekday|weekend|opening|open|now|from|hours|hour|our|are|EST|and|&'.split("|");
  74. for (twix=0; twix<killWords.length; twix++) {
  75. tempRegex = new RegExp('\\b'+killWords[twix]+'\\b', "g");
  76. inputHoursParse = inputHoursParse.replace(tempRegex,'');
  77. }
  78.  
  79. // replace day terms with double caps
  80. for (let dayKey in this.DAYS_OF_THE_WEEK) {
  81. if (this.DAYS_OF_THE_WEEK.hasOwnProperty(dayKey)) {
  82. let tempDayList = this.DAYS_OF_THE_WEEK[dayKey];
  83. for (var tdix=0; tdix<tempDayList.length; tdix++) {
  84. tempRegex = new RegExp(tempDayList[tdix]+'(?!a-z)', "g");
  85. inputHoursParse = inputHoursParse.replace(tempRegex,dayKey);
  86. }
  87. }
  88. }
  89.  
  90. // Replace dates
  91. for (let monthKey in this.MONTHS_OF_THE_YEAR) {
  92. if (this.MONTHS_OF_THE_YEAR.hasOwnProperty(monthKey)) {
  93. let tempMonthList = this.MONTHS_OF_THE_YEAR[monthKey];
  94. for (var tmix=0; tmix<tempMonthList.length; tmix++) {
  95. tempRegex = new RegExp(tempMonthList[tmix]+'\\.? ?\\d{1,2}\\,? ?201\\d{1}', "g");
  96. inputHoursParse = inputHoursParse.replace(tempRegex,' ');
  97. tempRegex = new RegExp(tempMonthList[tmix]+'\\.? ?\\d{1,2}', "g");
  98. inputHoursParse = inputHoursParse.replace(tempRegex,' ');
  99. }
  100. }
  101. }
  102.  
  103. // replace any periods between hours with colons
  104. inputHoursParse = inputHoursParse.replace(/(\d{1,2})\.(\d{2})/g, '$1:$2');
  105. // remove remaining periods
  106. inputHoursParse = inputHoursParse.replace(/\./g, '');
  107. // remove any non-hour colons between letters and numbers and on string ends
  108. inputHoursParse = inputHoursParse.replace(/(\D+)\:(\D+)/g, '$1 $2').replace(/^ *\:/g, ' ').replace(/\: *$/g, ' ');
  109. // replace am/pm with AA/PP
  110. inputHoursParse = inputHoursParse.replace(/ *pm/g,'PP').replace(/ *am/g,'AA');
  111. inputHoursParse = inputHoursParse.replace(/ *p\.m\./g,'PP').replace(/ *a\.m\./g,'AA');
  112. inputHoursParse = inputHoursParse.replace(/ *p\.m/g,'PP').replace(/ *a\.m/g,'AA');
  113. inputHoursParse = inputHoursParse.replace(/ *p/g,'PP').replace(/ *a/g,'AA');
  114. // tighten up dashes
  115. inputHoursParse = inputHoursParse.replace(/\- {1,}/g,'-').replace(/ {1,}\-/g,'-');
  116. inputHoursParse = inputHoursParse.replace(/^(00:00-00:00)$/g,'MM-UU$1');
  117.  
  118. // Change all MTWRFSU to doubles, if any other letters return false
  119. if (inputHoursParse.match(/[bcdeghijklnoqvxyz]/g) !== null) {
  120. returnVal.parseError = true;
  121. return returnVal;
  122. } else {
  123. inputHoursParse = inputHoursParse.replace(/m/g,'MM').replace(/t/g,'TT').replace(/w/g,'WW').replace(/r/g,'RR');
  124. inputHoursParse = inputHoursParse.replace(/f/g,'FF').replace(/s/g,'SS').replace(/u/g,'UU');
  125. }
  126.  
  127. // tighten up spaces
  128. inputHoursParse = inputHoursParse.replace(/ {2,}/g,' ');
  129. inputHoursParse = inputHoursParse.replace(/ {1,}AA/g,'AA');
  130. inputHoursParse = inputHoursParse.replace(/ {1,}PP/g,'PP');
  131. // Expand hours into XX:XX format
  132. for (var asdf=0; asdf<5; asdf++) { // repeat a few times to catch any skipped regex matches
  133. inputHoursParse = inputHoursParse.replace(/([^0-9\:])(\d{1})([^0-9\:])/g, '$10$2:00$3');
  134. inputHoursParse = inputHoursParse.replace(/^(\d{1})([^0-9\:])/g, '0$1:00$2');
  135. inputHoursParse = inputHoursParse.replace(/([^0-9\:])(\d{1})$/g, '$10$2:00');
  136.  
  137. inputHoursParse = inputHoursParse.replace(/([^0-9\:])(\d{2})([^0-9\:])/g, '$1$2:00$3');
  138. inputHoursParse = inputHoursParse.replace(/^(\d{2})([^0-9\:])/g, '$1:00$2');
  139. inputHoursParse = inputHoursParse.replace(/([^0-9\:])(\d{2})$/g, '$1$2:00');
  140.  
  141. inputHoursParse = inputHoursParse.replace(/(\D)(\d{1})(\d{2}\D)/g, '$10$2:$3');
  142. inputHoursParse = inputHoursParse.replace(/^(\d{1})(\d{2}\D)/g, '0$1:$2');
  143. inputHoursParse = inputHoursParse.replace(/(\D)(\d{1})(\d{2})$/g, '$10$2:$3');
  144.  
  145. inputHoursParse = inputHoursParse.replace(/(\D\d{2})(\d{2}\D)/g, '$1:$2');
  146. inputHoursParse = inputHoursParse.replace(/^(\d{2})(\d{2}\D)/g, '$1:$2');
  147. inputHoursParse = inputHoursParse.replace(/(\D\d{2})(\d{2})$/g, '$1:$2');
  148.  
  149. inputHoursParse = inputHoursParse.replace(/(\D)(\d{1}\:)/g, '$10$2');
  150. inputHoursParse = inputHoursParse.replace(/^(\d{1}\:)/g, '0$1');
  151. }
  152.  
  153. // replace 12AM range with 00
  154. inputHoursParse = inputHoursParse.replace( /12(\:\d{2}AA)/g, '00$1');
  155. // Change PM hours to 24hr time
  156. while (inputHoursParse.match(/\d{2}\:\d{2}PP/) !== null) {
  157. tfHourTemp = inputHoursParse.match(/(\d{2})\:\d{2}PP/)[1];
  158. tfHourTemp = parseInt(tfHourTemp) % 12 + 12;
  159. inputHoursParse = inputHoursParse.replace(/\d{2}(\:\d{2})PP/,tfHourTemp.toString()+'$1');
  160. }
  161. // kill the AA
  162. inputHoursParse = inputHoursParse.replace( /AA/g, '');
  163.  
  164. // Side check for tabular input
  165. var inputHoursParseTab = inputHoursParse.replace( /[^A-Z0-9\:-]/g, ' ').replace( / {2,}/g, ' ');
  166. inputHoursParseTab = inputHoursParseTab.replace( /^ +/g, '').replace( / {1,}$/g, '');
  167. if (inputHoursParseTab.match(/[A-Z]{2}\:?\-? [A-Z]{2}\:?\-? [A-Z]{2}\:?\-? [A-Z]{2}\:?\-? [A-Z]{2}\:?\-?/g) !== null) {
  168. inputHoursParseTab = inputHoursParseTab.split(' ');
  169. var reorderThree = [0,7,14,1,8,15,2,9,16,3,10,17,4,11,18,5,12,19,6,13,20];
  170. var reorderTwo = [0,7,1,8,2,9,3,10,4,11,5,12,6,13];
  171. var inputHoursParseReorder = [], reix;
  172. if (inputHoursParseTab.length === 21) {
  173. for (reix=0; reix<21; reix++) {
  174. inputHoursParseReorder.push(inputHoursParseTab[reorderThree[reix]]);
  175. }
  176. } else if (inputHoursParseTab.length === 18) {
  177. for (reix=0; reix<18; reix++) {
  178. inputHoursParseReorder.push(inputHoursParseTab[reorderThree[reix]]);
  179. }
  180. } else if (inputHoursParseTab.length === 15) {
  181. for (reix=0; reix<15; reix++) {
  182. inputHoursParseReorder.push(inputHoursParseTab[reorderThree[reix]]);
  183. }
  184. } else if (inputHoursParseTab.length === 14) {
  185. for (reix=0; reix<14; reix++) {
  186. inputHoursParseReorder.push(inputHoursParseTab[reorderTwo[reix]]);
  187. }
  188. } else if (inputHoursParseTab.length === 12) {
  189. for (reix=0; reix<12; reix++) {
  190. inputHoursParseReorder.push(inputHoursParseTab[reorderTwo[reix]]);
  191. }
  192. } else if (inputHoursParseTab.length === 10) {
  193. for (reix=0; reix<10; reix++) {
  194. inputHoursParseReorder.push(inputHoursParseTab[reorderTwo[reix]]);
  195. }
  196. }
  197.  
  198. if (inputHoursParseReorder.length > 9) {
  199. inputHoursParseReorder = inputHoursParseReorder.join(' ');
  200. inputHoursParseReorder = inputHoursParseReorder.replace(/(\:\d{2}) (\d{2}\:)/g, '$1-$2');
  201. inputHoursParse = inputHoursParseReorder;
  202. }
  203.  
  204. }
  205.  
  206.  
  207. // remove colons after Days field
  208. inputHoursParse = inputHoursParse.replace(/(\D+)\:/g, '$1 ');
  209.  
  210. // Find any double sets
  211. inputHoursParse = inputHoursParse.replace(/([A-Z \-]{2,}) *(\d{2}\:\d{2} *\-{1} *\d{2}\:\d{2}) *(\d{2}\:\d{2} *\-{1} *\d{2}\:\d{2})/g, '$1$2$1$3');
  212. inputHoursParse = inputHoursParse.replace(/(\d{2}\:\d{2}) *(\d{2}\:\d{2})/g, '$1-$2');
  213.  
  214. // remove all spaces
  215. inputHoursParse = inputHoursParse.replace( / */g, '');
  216.  
  217. // Remove any dashes acting as Day separators for 3+ days ("M-W-F")
  218. inputHoursParse = inputHoursParse.replace( /([A-Z]{2})-([A-Z]{2})-([A-Z]{2})-([A-Z]{2})-([A-Z]{2})-([A-Z]{2})-([A-Z]{2})/g, '$1$2$3$4$5$6$7');
  219. inputHoursParse = inputHoursParse.replace( /([A-Z]{2})-([A-Z]{2})-([A-Z]{2})-([A-Z]{2})-([A-Z]{2})-([A-Z]{2})/g, '$1$2$3$4$5$6');
  220. inputHoursParse = inputHoursParse.replace( /([A-Z]{2})-([A-Z]{2})-([A-Z]{2})-([A-Z]{2})-([A-Z]{2})/g, '$1$2$3$4$5');
  221. inputHoursParse = inputHoursParse.replace( /([A-Z]{2})-([A-Z]{2})-([A-Z]{2})-([A-Z]{2})/g, '$1$2$3$4');
  222. inputHoursParse = inputHoursParse.replace( /([A-Z]{2})-([A-Z]{2})-([A-Z]{2})/g, '$1$2$3');
  223.  
  224. // parse any 'through' type terms on the day ranges (MM-RR --> MMTTWWRR)
  225. while (inputHoursParse.match(/[A-Z]{2}\-[A-Z]{2}/) !== null) {
  226. tfDaysTemp = inputHoursParse.match(/([A-Z]{2})\-([A-Z]{2})/);
  227. var startDayIX = this.DAY_CODE_VECTOR.indexOf(tfDaysTemp[1]);
  228. newDayCodeVec = [tfDaysTemp[1]];
  229. for (var dcvix=startDayIX+1; dcvix<startDayIX+7; dcvix++) {
  230. newDayCodeVec.push(this.DAY_CODE_VECTOR[dcvix]);
  231. if (tfDaysTemp[2] === this.DAY_CODE_VECTOR[dcvix]) {
  232. break;
  233. }
  234. }
  235. newDayCodeVec = newDayCodeVec.join('');
  236. inputHoursParse = inputHoursParse.replace(/[A-Z]{2}\-[A-Z]{2}/,newDayCodeVec);
  237. }
  238.  
  239. // split the string between numerical and letter characters
  240. inputHoursParse = inputHoursParse.replace(/([A-Z])\-?\:?([0-9])/g,'$1|$2');
  241. inputHoursParse = inputHoursParse.replace(/([0-9])\-?\:?([A-Z])/g,'$1|$2');
  242. inputHoursParse = inputHoursParse.replace(/(\d{2}\:\d{2})\:00/g,'$1'); // remove seconds
  243. inputHoursParse = inputHoursParse.split("|");
  244.  
  245. var daysVec = [], hoursVec = [];
  246. for (tsix=0; tsix<inputHoursParse.length; tsix++) {
  247. if (inputHoursParse[tsix][0].match(/[A-Z]/) !== null) {
  248. daysVec.push(inputHoursParse[tsix]);
  249. } else if (inputHoursParse[tsix][0].match(/[0-9]/) !== null) {
  250. hoursVec.push(inputHoursParse[tsix]);
  251. } else {
  252. returnVal.parseError = true;
  253. return returnVal;
  254. }
  255. }
  256.  
  257. // check that the dayArray and hourArray lengths correspond
  258. if ( daysVec.length !== hoursVec.length ) {
  259. returnVal.parseError = true;
  260. return returnVal;
  261. }
  262.  
  263. // Combine days with the same hours in the same vector
  264. var newDaysVec = [], newHoursVec = [], hrsIX;
  265. for (tsix=0; tsix<daysVec.length; tsix++) {
  266. if (hoursVec[tsix] !== '99:99-99:99') { // Don't add the closed days
  267. hrsIX = newHoursVec.indexOf(hoursVec[tsix]);
  268. if (hrsIX > -1) {
  269. newDaysVec[hrsIX] = newDaysVec[hrsIX] + daysVec[tsix];
  270. } else {
  271. newDaysVec.push(daysVec[tsix]);
  272. newHoursVec.push(hoursVec[tsix]);
  273. }
  274. }
  275. }
  276.  
  277. var hoursObjectArray = [], hoursObjectArrayMinDay = [], hoursObjectArraySorted = [], hoursObjectAdd, daysObjArray, toFromSplit;
  278. for (tsix=0; tsix<newDaysVec.length; tsix++) {
  279. hoursObjectAdd = {};
  280. daysObjArray = [];
  281. toFromSplit = newHoursVec[tsix].match(/(\d{2}\:\d{2})\-(\d{2}\:\d{2})/);
  282. if (toFromSplit === null) {
  283. returnVal.parseError = true;
  284. return returnVal;
  285. } else { // Check for hours outside of 0-23 and 0-59
  286. var hourCheck = toFromSplit[1].match(/(\d{2})\:/)[1];
  287. if (hourCheck>23 || hourCheck < 0) {
  288. returnVal.parseError = true;
  289. return returnVal;
  290. }
  291. hourCheck = toFromSplit[2].match(/(\d{2})\:/)[1];
  292. if (hourCheck>23 || hourCheck < 0) {
  293. returnVal.parseError = true;
  294. return returnVal;
  295. }
  296. hourCheck = toFromSplit[1].match(/\:(\d{2})/)[1];
  297. if (hourCheck>59 || hourCheck < 0) {
  298. returnVal.parseError = true;
  299. return returnVal;
  300. }
  301. hourCheck = toFromSplit[2].match(/\:(\d{2})/)[1];
  302. if (hourCheck>59 || hourCheck < 0) {
  303. returnVal.parseError = true;
  304. return returnVal;
  305. }
  306. }
  307. // Make the days object
  308. if ( newDaysVec[tsix].indexOf('MM') > -1 ) {
  309. daysObjArray.push(1);
  310. }
  311. if ( newDaysVec[tsix].indexOf('TT') > -1 ) {
  312. daysObjArray.push(2);
  313. }
  314. if ( newDaysVec[tsix].indexOf('WW') > -1 ) {
  315. daysObjArray.push(3);
  316. }
  317. if ( newDaysVec[tsix].indexOf('RR') > -1 ) {
  318. daysObjArray.push(4);
  319. }
  320. if ( newDaysVec[tsix].indexOf('FF') > -1 ) {
  321. daysObjArray.push(5);
  322. }
  323. if ( newDaysVec[tsix].indexOf('SS') > -1 ) {
  324. daysObjArray.push(6);
  325. }
  326. if ( newDaysVec[tsix].indexOf('UU') > -1 ) {
  327. daysObjArray.push(0);
  328. }
  329. // build the hours object
  330. hoursObjectAdd.fromHour = toFromSplit[1];
  331. hoursObjectAdd.toHour = toFromSplit[2];
  332. hoursObjectAdd.days = daysObjArray.sort();
  333. hoursObjectArray.push(hoursObjectAdd);
  334. // track the order
  335. if (hoursObjectAdd.days.length > 1 && hoursObjectAdd.days[0] === 0) {
  336. hoursObjectArrayMinDay.push( hoursObjectAdd.days[1] * 100 + parseInt(toFromSplit[1][0])*10 + parseInt(toFromSplit[1][1]) );
  337. } else {
  338. hoursObjectArrayMinDay.push( (((hoursObjectAdd.days[0]+6)%7)+1) * 100 + parseInt(toFromSplit[1][0])*10 + parseInt(toFromSplit[1][1]) );
  339. }
  340. }
  341. this._sortWithIndex(hoursObjectArrayMinDay);
  342. for (var hoaix=0; hoaix < hoursObjectArrayMinDay.length; hoaix++) {
  343. hoursObjectArraySorted.push(hoursObjectArray[hoursObjectArrayMinDay.sortIndices[hoaix]]);
  344. }
  345. if ( !this._checkHours(hoursObjectArraySorted) ) {
  346. returnVal.hours = hoursObjectArraySorted;
  347. returnVal.overlappingHours = true;
  348. return returnVal;
  349. } else if ( this._hasSameOpenCloseTimes(hoursObjectArraySorted) ) {
  350. returnVal.hours = hoursObjectArraySorted;
  351. returnVal.sameOpenAndCloseTimes = true;
  352. return returnVal;
  353. } else {
  354. for ( var ohix=0; ohix<hoursObjectArraySorted.length; ohix++ ) {
  355. if ( hoursObjectArraySorted[ohix].days.length === 2 && hoursObjectArraySorted[ohix].days[0] === 0 && hoursObjectArraySorted[ohix].days[1] === 1) {
  356. // separate hours
  357. hoursObjectArraySorted.push({days: [0], fromHour: hoursObjectArraySorted[ohix].fromHour, toHour: hoursObjectArraySorted[ohix].toHour});
  358. hoursObjectArraySorted[ohix].days = [1];
  359. }
  360. }
  361. }
  362. returnVal.hours = hoursObjectArray;
  363. return returnVal;
  364. }
  365.  
  366. // function to check overlapping hours
  367. _checkHours(hoursObj) {
  368. if (hoursObj.length === 1) {
  369. return true;
  370. }
  371. var daysObj, fromHourTemp, toHourTemp;
  372. for (var day2Ch=0; day2Ch<7; day2Ch++) { // Go thru each day of the week
  373. daysObj = [];
  374. for ( var hourSet = 0; hourSet < hoursObj.length; hourSet++ ) { // For each set of hours
  375. if (hoursObj[hourSet].days.indexOf(day2Ch) > -1) { // pull out hours that are for the current day, add 2400 if it goes past midnight, and store
  376. fromHourTemp = hoursObj[hourSet].fromHour.replace(/\:/g,'');
  377. toHourTemp = hoursObj[hourSet].toHour.replace(/\:/g,'');
  378. if (toHourTemp <= fromHourTemp) {
  379. toHourTemp = parseInt(toHourTemp) + 2400;
  380. }
  381. daysObj.push([fromHourTemp, toHourTemp]);
  382. }
  383. }
  384. if (daysObj.length > 1) { // If there's multiple hours for the day, check them for overlap
  385. for ( var hourSetCheck2 = 1; hourSetCheck2 < daysObj.length; hourSetCheck2++ ) {
  386. for ( var hourSetCheck1 = 0; hourSetCheck1 < hourSetCheck2; hourSetCheck1++ ) {
  387. if ( daysObj[hourSetCheck2][0] > daysObj[hourSetCheck1][0] && daysObj[hourSetCheck2][0] < daysObj[hourSetCheck1][1] ) {
  388. return false;
  389. }
  390. if ( daysObj[hourSetCheck2][1] > daysObj[hourSetCheck1][0] && daysObj[hourSetCheck2][1] < daysObj[hourSetCheck1][1] ) {
  391. return false;
  392. }
  393. }
  394. }
  395. }
  396. }
  397. return true;
  398. }
  399.  
  400. _hasSameOpenCloseTimes(hoursObj) {
  401. var fromHourTemp, toHourTemp;
  402. for ( var hourSet = 0; hourSet < hoursObj.length; hourSet++ ) { // For each set of hours
  403. fromHourTemp = hoursObj[hourSet].fromHour;
  404. toHourTemp = hoursObj[hourSet].toHour;
  405. if (fromHourTemp !== '00:00' && fromHourTemp === toHourTemp) {
  406. // If open and close times are the same, don't parse.
  407. return true;
  408. }
  409. }
  410. return false;
  411. }
  412.  
  413. _sortWithIndex(toSort) {
  414. for (var i = 0; i < toSort.length; i++) {
  415. toSort[i] = [toSort[i], i];
  416. }
  417. toSort.sort(function(left, right) {
  418. return left[0] < right[0] ? -1 : 1;
  419. });
  420. toSort.sortIndices = [];
  421. for (var j = 0; j < toSort.length; j++) {
  422. toSort.sortIndices.push(toSort[j][1]);
  423. toSort[j] = toSort[j][0];
  424. }
  425. return toSort;
  426. }
  427. // delete this later...
  428. _unused() {}
  429. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址