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/243565/WME%20Utils%20-%20HoursParser.js

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