WME Utils - HoursParser

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

当前为 2018-01-15 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/37486/243588/WME%20Utils%20-%20HoursParser.js

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