expression.js 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409
  1. var test = require('tap').test;
  2. var CronExpression = require('../lib/expression');
  3. var CronDate = require('../lib/date');
  4. test('empty expression test', function(t) {
  5. try {
  6. var interval = CronExpression.parse('');
  7. t.ok(interval, 'Interval parsed');
  8. var date = new CronDate();
  9. date.addMinute();
  10. var next = interval.next();
  11. t.ok(next, 'Found next scheduled interval');
  12. t.equal(next.getMinutes(), date.getMinutes(), 'Schedule matches');
  13. t.end();
  14. } catch (err) {
  15. t.ifError(err, 'Interval parse error');
  16. }
  17. });
  18. test('default expression test', function(t) {
  19. try {
  20. var interval = CronExpression.parse('* * * * *');
  21. t.ok(interval, 'Interval parsed');
  22. var date = new CronDate();
  23. date.addMinute();
  24. var next = interval.next();
  25. t.ok(next, 'Found next scheduled interval');
  26. t.equal(next.getMinutes(), date.getMinutes(), 'Schedule matches');
  27. } catch (err) {
  28. t.ifError(err, 'Interval parse error');
  29. }
  30. t.end();
  31. });
  32. test('default expression (tab separate) test', function(t) {
  33. try {
  34. var interval = CronExpression.parse('* * * * *');
  35. t.ok(interval, 'Interval parsed');
  36. var date = new CronDate();
  37. date.addMinute();
  38. var next = interval.next();
  39. t.ok(next, 'Found next scheduled interval');
  40. t.equal(next.getMinutes(), date.getMinutes(), 'Schedule matches');
  41. } catch (err) {
  42. t.ifError(err, 'Interval parse error');
  43. }
  44. t.end();
  45. });
  46. test('default expression (multi-space separated) test 1', function(t) {
  47. try {
  48. var interval = CronExpression.parse('* \t*\t\t *\t * \t\t*');
  49. t.ok(interval, 'Interval parsed');
  50. var date = new CronDate();
  51. date.addMinute();
  52. var next = interval.next();
  53. t.ok(next, 'Found next scheduled interval');
  54. t.equal(next.getMinutes(), date.getMinutes(), 'Schedule matches');
  55. } catch (err) {
  56. t.ifError(err, 'Interval parse error');
  57. }
  58. t.end();
  59. });
  60. test('default expression (multi-space separated) test 1', function(t) {
  61. try {
  62. var interval = CronExpression.parse('* \t *\t \t * * \t \t *');
  63. t.ok(interval, 'Interval parsed');
  64. var date = new CronDate();
  65. date.addMinute();
  66. var next = interval.next();
  67. t.ok(next, 'Found next scheduled interval');
  68. t.equal(next.getMinutes(), date.getMinutes(), 'Schedule matches');
  69. } catch (err) {
  70. t.ifError(err, 'Interval parse error');
  71. }
  72. t.end();
  73. });
  74. test('value out of the range', function(t) {
  75. t.throws(function() {
  76. CronExpression.parse('61 * * * * *');
  77. }, new Error('Constraint error, got value 61 expected range 0-59'));
  78. t.end();
  79. });
  80. test('second value out of the range', function(t) {
  81. t.throws(function() {
  82. CronExpression.parse('-1 * * * * *');
  83. }, new Error('Constraint error, got value -1 expected range 0-59'));
  84. t.end();
  85. });
  86. test('invalid range', function(t) {
  87. t.throws(function() {
  88. CronExpression.parse('- * * * * *');
  89. }, new Error('Invalid range: -'));
  90. t.end();
  91. });
  92. test('minute value out of the range', function(t) {
  93. t.throws(function() {
  94. CronExpression.parse('* 32,72 * * * *');
  95. }, new Error('Constraint error, got value 72 expected range 0-59'));
  96. t.end();
  97. });
  98. test('hour value out of the range', function(t) {
  99. t.throws(function() {
  100. CronExpression.parse('* * 12-36 * * *');
  101. }, new Error('Constraint error, got range 12-36 expected range 0-23'));
  102. t.end();
  103. });
  104. test('day of the month value out of the range', function(t) {
  105. t.throws(function() {
  106. CronExpression.parse('* * * 10-15,40 * *');
  107. }, ('Constraint error, got value 40 expected range 1-31'));
  108. t.end();
  109. });
  110. test('month value out of the range', function(t) {
  111. t.throws(function() {
  112. CronExpression.parse('* * * * */10,12-13 *');
  113. }, new Error('Constraint error, got range 12-13 expected range 1-12'));
  114. t.end();
  115. });
  116. test('day of the week value out of the range', function(t) {
  117. t.throws(function() {
  118. CronExpression.parse('* * * * * 9');
  119. }, new Error('Constraint error, got value 9 expected range 0-7'));
  120. t.end();
  121. });
  122. test('invalid expression that contains too many fields', function (t) {
  123. t.throws(function() {
  124. CronExpression.parse('* * * * * * * *ASD');
  125. }, new Error('Invalid cron expression'));
  126. t.end();
  127. });
  128. test('invalid explicit day of month definition', function(t) {
  129. t.throws(function() {
  130. const iter = CronExpression.parse('0 0 31 4 *');
  131. iter.next();
  132. }, new Error('Invalid explicit day of month definition'));
  133. t.end();
  134. });
  135. test('incremental minutes expression test', function(t) {
  136. try {
  137. var interval = CronExpression.parse('*/3 * * * *');
  138. t.ok(interval, 'Interval parsed');
  139. var next = interval.next();
  140. t.ok(next, 'Found next scheduled interval');
  141. t.equal(next.getMinutes() % 3, 0, 'Schedule matches');
  142. } catch (err) {
  143. t.ifError(err, 'Interval parse error');
  144. }
  145. t.end();
  146. });
  147. test('fixed expression test', function(t) {
  148. try {
  149. var interval = CronExpression.parse('10 2 12 8 0');
  150. t.ok(interval, 'Interval parsed');
  151. var next = interval.next();
  152. t.ok(next, 'Found next scheduled interval');
  153. t.ok(next.getDay() === 0 || next.getDate() === 12, 'Day or day of Month matches');
  154. t.equal(next.getMonth(), 7, 'Month matches');
  155. t.equal(next.getHours(), 2, 'Hour matches');
  156. t.equal(next.getMinutes(), 10, 'Minute matches');
  157. } catch (err) {
  158. t.ifError(err, 'Interval parse error');
  159. }
  160. t.end();
  161. });
  162. test('invalid characters test - symbol', function(t) {
  163. t.throws(function() {
  164. CronExpression.parse('10 ! 12 8 0');
  165. }, new Error('Invalid characters, got value: !'));
  166. t.end();
  167. });
  168. test('invalid characters test - letter', function(t) {
  169. t.throws(function() {
  170. CronExpression.parse('10 x 12 8 0');
  171. }, new Error('Invalid characters, got value: x'));
  172. t.end();
  173. });
  174. test('invalid characters test - parentheses', function(t) {
  175. t.throws(function() {
  176. CronExpression.parse('10 ) 12 8 0');
  177. }, new Error('Invalid characters, got value: )'));
  178. t.end();
  179. });
  180. test('interval with invalid characters test', function(t) {
  181. t.throws(function() {
  182. CronExpression.parse('10 */A 12 8 0');
  183. }, new Error('Invalid characters, got value: */A'));
  184. t.end();
  185. });
  186. test('range with invalid characters test', function(t) {
  187. t.throws(function() {
  188. CronExpression.parse('10 0-z 12 8 0');
  189. }, new Error('Invalid characters, got value: 0-z'));
  190. t.end();
  191. });
  192. test('group with invalid characters test', function(t) {
  193. t.throws(function() {
  194. CronExpression.parse('10 0,1,z 12 8 0');
  195. }, new Error('Invalid characters, got value: 0,1,z'));
  196. t.end();
  197. });
  198. test('invalid expression which has repeat 0 times', function(t) {
  199. t.throws(function() {
  200. CronExpression.parse('0 */0 * * *');
  201. }, new Error('Constraint error, cannot repeat at every 0 time.'));
  202. t.end();
  203. });
  204. test('invalid expression which has repeat negative number times', function(t) {
  205. t.throws(function() {
  206. CronExpression.parse('0 */-5 * * *');
  207. }, new Error('Constraint error, cannot repeat at every -5 time.'));
  208. t.end();
  209. });
  210. test('range test with value and repeat (second)', function(t) {
  211. var options = {
  212. currentDate: new CronDate('Wed, 26 Dec 2012 14:38:53')
  213. };
  214. var interval = CronExpression.parse('0/30 * * * * ?', options);
  215. t.ok(interval, 'Interval parsed');
  216. var next = interval.next();
  217. t.equal(next.getSeconds(), 0);
  218. next = interval.next();
  219. t.equal(next.getSeconds(), 30);
  220. next = interval.next();
  221. t.equal(next.getSeconds(), 0);
  222. t.end();
  223. });
  224. test('range test with value and repeat (minute)', function(t) {
  225. var options = {
  226. currentDate: new CronDate('Wed, 26 Dec 2012 14:38:53')
  227. };
  228. var interval = CronExpression.parse('6/23 * * * *', options);
  229. t.ok(interval, 'Interval parsed');
  230. var next = interval.next();
  231. t.equal(next.getMinutes(), 52);
  232. next = interval.next();
  233. t.equal(next.getMinutes(), 6);
  234. next = interval.next();
  235. t.equal(next.getMinutes(), 29);
  236. next = interval.next();
  237. t.equal(next.getMinutes(), 52);
  238. t.end();
  239. });
  240. test('range test with iterator', function(t) {
  241. try {
  242. var interval = CronExpression.parse('10-30 2 12 8 0');
  243. t.ok(interval, 'Interval parsed');
  244. var intervals = interval.iterate(20);
  245. t.ok(intervals, 'Found intervals');
  246. for (var i = 0, c = intervals.length; i < c; i++) {
  247. var next = intervals[i];
  248. t.ok(next, 'Found next scheduled interval');
  249. t.ok(next.getDay() === 0 || next.getDate() === 12, 'Day or day of month matches');
  250. t.equal(next.getMonth(), 7, 'Month matches');
  251. t.equal(next.getHours(), 2, 'Hour matches');
  252. t.equal(next.getMinutes(), 10 + i, 'Minute matches');
  253. }
  254. } catch (err) {
  255. t.ifError(err, 'Interval parse error');
  256. }
  257. t.end();
  258. });
  259. test('incremental range test with iterator', function(t) {
  260. try {
  261. var interval = CronExpression.parse('10-30/2 2 12 8 0');
  262. t.ok(interval, 'Interval parsed');
  263. var intervals = interval.iterate(10);
  264. t.ok(intervals, 'Found intervals');
  265. for (var i = 0, c = intervals.length; i < c; i++) {
  266. var next = intervals[i];
  267. t.ok(next, 'Found next scheduled interval');
  268. t.ok(next.getDay() === 0 || next.getDate() === 12, 'Day or day of month matches');
  269. t.equal(next.getMonth(), 7, 'Month matches');
  270. t.equal(next.getHours(), 2, 'Hour matches');
  271. t.equal(next.getMinutes(), 10 + (i * 2), 'Minute matches');
  272. }
  273. } catch (err) {
  274. t.ifError(err, 'Interval parse error');
  275. }
  276. t.end();
  277. });
  278. test('predefined expression', function(t) {
  279. try {
  280. var interval = CronExpression.parse('@yearly');
  281. t.ok(interval, 'Interval parsed');
  282. var date = new CronDate();
  283. date.addYear();
  284. var next = interval.next();
  285. t.ok(next, 'Found next scheduled interval');
  286. t.equal(next.getFullYear(), date.getFullYear(), 'Year matches');
  287. } catch (err) {
  288. t.ifError(err, 'Interval parse error');
  289. }
  290. t.end();
  291. });
  292. test('expression limited with start and end date', function(t) {
  293. try {
  294. var options = {
  295. currentDate: new CronDate('Wed, 26 Dec 2012 14:38:53'),
  296. startDate: new CronDate('Wed, 26 Dec 2012 12:40:00'),
  297. endDate: new CronDate('Wed, 26 Dec 2012 16:40:00')
  298. };
  299. var interval = CronExpression.parse('*/20 * * * *', options);
  300. t.ok(interval, 'Interval parsed');
  301. var dates = interval.iterate(10);
  302. t.equal(dates.length, 7, 'Dates count matches for positive iteration');
  303. interval.reset();
  304. var dates = interval.iterate(-10);
  305. t.equal(dates.length, 6, 'Dates count matches for negative iteration');
  306. interval.reset();
  307. // Forward iteration
  308. var next = interval.next();
  309. t.equal(next.getHours(), 14, 'Hour matches');
  310. t.equal(next.getMinutes(), 40, 'Minute matches');
  311. next = interval.next();
  312. t.equal(next.getHours(), 15, 'Hour matches');
  313. t.equal(next.getMinutes(), 0, 'Minute matches');
  314. next = interval.next();
  315. t.equal(next.getHours(), 15, 'Hour matches');
  316. t.equal(next.getMinutes(), 20, 'Minute matches');
  317. next = interval.next();
  318. t.equal(next.getHours(), 15, 'Hour matches');
  319. t.equal(next.getMinutes(), 40, 'Minute matches');
  320. next = interval.next();
  321. t.equal(next.getHours(), 16, 'Hour matches');
  322. t.equal(next.getMinutes(), 0, 'Minute matches');
  323. next = interval.next();
  324. t.equal(next.getHours(), 16, 'Hour matches');
  325. t.equal(next.getMinutes(), 20, 'Minute matches');
  326. next = interval.next();
  327. t.equal(next.getHours(), 16, 'Hour matches');
  328. t.equal(next.getMinutes(), 40, 'Minute matches');
  329. try {
  330. interval.next();
  331. t.ok(false, 'Should fail');
  332. } catch (e) {
  333. t.ok(true, 'Failed as expected');
  334. }
  335. next = interval.prev();
  336. t.equal(next.getHours(), 16, 'Hour matches');
  337. t.equal(next.getMinutes(), 20, 'Minute matches');
  338. interval.reset();
  339. // Backward iteration
  340. var prev = interval.prev();
  341. t.equal(prev.getHours(), 14, 'Hour matches');
  342. t.equal(prev.getMinutes(), 20, 'Minute matches');
  343. prev = interval.prev();
  344. t.equal(prev.getHours(), 14, 'Hour matches');
  345. t.equal(prev.getMinutes(), 0, 'Minute matches');
  346. prev = interval.prev();
  347. t.equal(prev.getHours(), 13, 'Hour matches');
  348. t.equal(prev.getMinutes(), 40, 'Minute matches');
  349. prev = interval.prev();
  350. t.equal(prev.getHours(), 13, 'Hour matches');
  351. t.equal(prev.getMinutes(), 20, 'Minute matches');
  352. prev = interval.prev();
  353. t.equal(prev.getHours(), 13, 'Hour matches');
  354. t.equal(prev.getMinutes(), 0, 'Minute matches');
  355. prev = interval.prev();
  356. t.equal(prev.getHours(), 12, 'Hour matches');
  357. t.equal(prev.getMinutes(), 40, 'Minute matches');
  358. try {
  359. interval.prev();
  360. t.ok(false, 'Should fail');
  361. } catch (e) {
  362. t.ok(true, 'Failed as expected');
  363. }
  364. } catch (err) {
  365. t.ifError(err, 'Interval parse error');
  366. }
  367. t.end();
  368. });
  369. test('reset to given date', function(t){
  370. try {
  371. var options = {
  372. currentDate: new CronDate('Wed, 26 Dec 2012 14:38:53')
  373. };
  374. var interval = CronExpression.parse('*/20 * * * *', options);
  375. t.ok(interval, 'Interval parsed');
  376. // Forward iteration
  377. var next = interval.next();
  378. t.equal(next.getHours(), 14, 'Hour matches');
  379. t.equal(next.getMinutes(), 40, 'Minute matches');
  380. interval.reset(); // defaults to initial currentDate
  381. next = interval.next();
  382. t.equal(next.getHours(), 14, 'Hour matches');
  383. t.equal(next.getMinutes(), 40, 'Minute matches');
  384. interval.reset(new CronDate('Wed, 26 Dec 2012 17:23:53'));
  385. next = interval.next();
  386. t.equal(next.getHours(), 17, 'Hour matches');
  387. t.equal(next.getMinutes(), 40, 'Minute matches');
  388. next = interval.next();
  389. t.equal(next.getHours(), 18, 'Hour matches');
  390. t.equal(next.getMinutes(), 0, 'Minute matches');
  391. interval.reset(new Date('2019-06-18T08:18:36.000'));
  392. next = interval.prev();
  393. t.equal(next.getDate(), 18, 'Date matches');
  394. t.equal(next.getHours(), 8, 'Hour matches');
  395. t.equal(next.getMinutes(), 0, 'Minute matches');
  396. next = interval.prev();
  397. t.equal(next.getDate(), 18, 'Date matches');
  398. t.equal(next.getHours(), 7, 'Hour matches');
  399. t.equal(next.getMinutes(), 40, 'Minute matches');
  400. t.end();
  401. } catch (err) {
  402. t.ifError(err, 'Reset error');
  403. }
  404. });
  405. test('parse expression as UTC', function(t) {
  406. try {
  407. var options = {
  408. utc: true
  409. };
  410. var interval = CronExpression.parse('0 0 10 * * *', options);
  411. var date = interval.next();
  412. t.equal(date.getUTCHours(), 10, 'Correct UTC hour value');
  413. t.equal(date.getHours(), 10, 'Correct UTC hour value');
  414. interval = CronExpression.parse('0 */5 * * * *', options);
  415. var date = interval.next(), now = new Date();
  416. now.setMinutes(now.getMinutes() + 5 - (now.getMinutes() % 5));
  417. t.equal(date.getHours(), now.getUTCHours(), 'Correct local time for 5 minute interval');
  418. } catch (err) {
  419. t.ifError(err, 'UTC parse error');
  420. }
  421. t.end();
  422. });
  423. test('expression using days of week strings', function(t) {
  424. try {
  425. var interval = CronExpression.parse('15 10 * * MON-TUE');
  426. t.ok(interval, 'Interval parsed');
  427. var intervals = interval.iterate(8);
  428. t.ok(intervals, 'Found intervals');
  429. for (var i = 0, c = intervals.length; i < c; i++) {
  430. var next = intervals[i];
  431. var day = next.getDay();
  432. t.ok(next, 'Found next scheduled interval');
  433. t.ok(day == 1 || day == 2, 'Day matches')
  434. t.equal(next.getHours(), 10, 'Hour matches');
  435. t.equal(next.getMinutes(), 15, 'Minute matches');
  436. }
  437. } catch (err) {
  438. t.ifError(err, 'Interval parse error');
  439. }
  440. t.end();
  441. });
  442. test('expression using mixed days of week strings', function(t) {
  443. try {
  444. var options = {
  445. currentDate: new CronDate('Wed, 26 Dec 2012 14:38:53')
  446. };
  447. var interval = CronExpression.parse('15 10 * jAn-FeB mOn-tUE', options);
  448. t.ok(interval, 'Interval parsed');
  449. var intervals = interval.iterate(8);
  450. t.ok(intervals, 'Found intervals');
  451. for (var i = 0, c = intervals.length; i < c; i++) {
  452. var next = intervals[i];
  453. var day = next.getDay();
  454. var month = next.getMonth();
  455. t.ok(next, 'Found next scheduled interval');
  456. t.ok(month == 0 || month == 2, 'Month Matches');
  457. t.ok(day == 1 || day == 2, 'Day matches');
  458. t.equal(next.getHours(), 10, 'Hour matches');
  459. t.equal(next.getMinutes(), 15, 'Minute matches');
  460. }
  461. } catch (err) {
  462. t.ifError(err, 'Interval parse error');
  463. }
  464. t.end();
  465. });
  466. test('expression using non-standard second field (wildcard)', function(t) {
  467. try {
  468. var options = {
  469. currentDate: new CronDate('Wed, 26 Dec 2012 14:38:00'),
  470. endDate: new CronDate('Wed, 26 Dec 2012 15:40:00')
  471. };
  472. var interval = CronExpression.parse('* * * * * *', options);
  473. t.ok(interval, 'Interval parsed');
  474. var intervals = interval.iterate(10);
  475. t.ok(intervals, 'Found intervals');
  476. for (var i = 0, c = intervals.length; i < c; i++) {
  477. var next = intervals[i];
  478. t.ok(next, 'Found next scheduled interval');
  479. t.equal(next.getSeconds(), i + 1, 'Second matches');
  480. }
  481. } catch (err) {
  482. t.ifError(err, 'Interval parse error');
  483. }
  484. t.end();
  485. });
  486. test('expression using non-standard second field (step)', function(t) {
  487. try {
  488. var options = {
  489. currentDate: new CronDate('Wed, 26 Dec 2012 14:38:00'),
  490. endDate: new CronDate('Wed, 26 Dec 2012 15:40:00')
  491. };
  492. var interval = CronExpression.parse('*/20 * * * * *', options);
  493. t.ok(interval, 'Interval parsed');
  494. var intervals = interval.iterate(3);
  495. t.ok(intervals, 'Found intervals');
  496. t.equal(intervals[0].getSeconds(), 20, 'Second matches');
  497. t.equal(intervals[1].getSeconds(), 40, 'Second matches');
  498. t.equal(intervals[2].getSeconds(), 0, 'Second matches');
  499. } catch (err) {
  500. t.ifError(err, 'Interval parse error');
  501. }
  502. t.end();
  503. });
  504. test('expression using non-standard second field (range)', function(t) {
  505. try {
  506. var options = {
  507. currentDate: new CronDate('Wed, 26 Dec 2012 14:38:00'),
  508. endDate: new CronDate('Wed, 26 Dec 2012 15:40:00')
  509. };
  510. var interval = CronExpression.parse('20-40/10 * * * * *', options);
  511. t.ok(interval, 'Interval parsed');
  512. var intervals = interval.iterate(3);
  513. t.ok(intervals, 'Found intervals');
  514. for (var i = 0, c = intervals.length; i < c; i++) {
  515. var next = intervals[i];
  516. t.ok(next, 'Found next scheduled interval');
  517. t.equal(next.getSeconds(), 20 + (i * 10), 'Second matches');
  518. }
  519. } catch (err) {
  520. t.ifError(err, 'Interval parse error');
  521. }
  522. t.end();
  523. });
  524. test('expression using explicit month definition and */5 day of month step', function(t) {
  525. var firstIterator = CronExpression.parse('0 12 */5 6 *', {
  526. currentDate: '2019-06-01T11:00:00.000'
  527. });
  528. var firstExpectedDates = [
  529. new CronDate('2019-06-01T12:00:00.000'),
  530. new CronDate('2019-06-06T12:00:00.000'),
  531. new CronDate('2019-06-11T12:00:00.000'),
  532. new CronDate('2019-06-16T12:00:00.000'),
  533. new CronDate('2019-06-21T12:00:00.000'),
  534. new CronDate('2019-06-26T12:00:00.000'),
  535. new CronDate('2020-06-01T12:00:00.000')
  536. ];
  537. firstExpectedDates.forEach(function(expectedDate) {
  538. t.equal(expectedDate.toISOString(), firstIterator.next().toISOString());
  539. });
  540. var secondIterator = CronExpression.parse('0 15 */5 5 *', {
  541. currentDate: '2019-05-01T11:00:00.000'
  542. });
  543. var secondExpectedDates = [
  544. new CronDate('2019-05-01T15:00:00.000'),
  545. new CronDate('2019-05-06T15:00:00.000'),
  546. new CronDate('2019-05-11T15:00:00.000'),
  547. new CronDate('2019-05-16T15:00:00.000'),
  548. new CronDate('2019-05-21T15:00:00.000'),
  549. new CronDate('2019-05-26T15:00:00.000'),
  550. new CronDate('2019-05-31T15:00:00.000'),
  551. new CronDate('2020-05-01T15:00:00.000')
  552. ];
  553. secondExpectedDates.forEach(function(expectedDate) {
  554. t.equal(expectedDate.toISOString(), secondIterator.next().toISOString());
  555. });
  556. t.end();
  557. });
  558. test('day of month and week are both set', function(t) {
  559. try {
  560. var interval = CronExpression.parse('10 2 12 8 0');
  561. t.ok(interval, 'Interval parsed');
  562. var next = interval.next();
  563. t.ok(next, 'Found next scheduled interval');
  564. t.ok(next.getDay() === 0 || next.getDate() === 12, 'Day or day of month matches');
  565. t.equal(next.getMonth(), 7, 'Month matches');
  566. next = interval.next();
  567. t.ok(next, 'Found next scheduled interval');
  568. t.ok(next.getDay() === 0 || next.getDate() === 12, 'Day or day of month matches');
  569. t.equal(next.getMonth(), 7, 'Month matches');
  570. next = interval.next();
  571. t.ok(next, 'Found next scheduled interval');
  572. t.ok(next.getDay() === 0 || next.getDate() === 12, 'Day or day of month matches');
  573. t.equal(next.getMonth(), 7, 'Month matches');
  574. next = interval.next();
  575. t.ok(next, 'Found next scheduled interval');
  576. t.ok(next.getDay() === 0 || next.getDate() === 12, 'Day or day of month matches');
  577. t.equal(next.getMonth(), 7, 'Month matches');
  578. } catch (err) {
  579. t.ifError(err, 'Interval parse error');
  580. }
  581. t.end();
  582. });
  583. test('day of month is unspecified', function(t) {
  584. try {
  585. var interval = CronExpression.parse('10 2 ? * 3');
  586. t.ok(interval, 'Interval parsed');
  587. var next = interval.next();
  588. t.ok(next, 'Found next scheduled interal');
  589. t.ok(next.getDay() === 3, 'day of week matches');
  590. next = interval.next();
  591. t.ok(next, 'Found next scheduled interal');
  592. t.ok(next.getDay() === 3, 'day of week matches');
  593. next = interval.next();
  594. t.ok(next, 'Found next scheduled interal');
  595. t.ok(next.getDay() === 3, 'day of week matches');
  596. next = interval.next();
  597. t.ok(next, 'Found next scheduled interal');
  598. t.ok(next.getDay() === 3, 'day of week matches');
  599. } catch (err) {
  600. t.ifError(err, 'Interval parse error');
  601. }
  602. t.end();
  603. });
  604. test('day of week is unspecified', function(t) {
  605. try {
  606. var interval = CronExpression.parse('10 2 3,6 * ?');
  607. t.ok(interval, 'Interval parsed');
  608. var next = interval.next();
  609. t.ok(next, 'Found next scheduled interal');
  610. t.ok(next.getDate() === 3 || next.getDate() === 6, 'date matches');
  611. var prevDate = next.getDate();
  612. next = interval.next();
  613. t.ok(next, 'Found next scheduled interal');
  614. t.ok((next.getDate() === 3 || next.getDate() === 6) &&
  615. next.getDate() !== prevDate, 'date matches and is not previous date');
  616. prevDate = next.getDate();
  617. next = interval.next();
  618. t.ok(next, 'Found next scheduled interal');
  619. t.ok((next.getDate() === 3 || next.getDate() === 6) &&
  620. next.getDate() !== prevDate, 'date matches and is not previous date');
  621. prevDate = next.getDate();
  622. next = interval.next();
  623. t.ok(next, 'Found next scheduled interal');
  624. t.ok((next.getDate() === 3 || next.getDate() === 6) &&
  625. next.getDate() !== prevDate, 'date matches and is not previous date');
  626. } catch (err) {
  627. t.ifError(err, 'Interval parse error');
  628. }
  629. t.end();
  630. });
  631. test('Summertime bug test', function(t) {
  632. try {
  633. var month = new CronDate().getMonth() + 1;
  634. var interval = CronExpression.parse('0 0 0 1 '+month+' *');
  635. t.ok(interval, 'Interval parsed');
  636. var next = interval.next();
  637. // Before fix the bug it was getting a timeout error if you are
  638. // in a timezone that changes the DST to ST in the hour 00:00h.
  639. t.ok(next, 'Found next scheduled interval');
  640. } catch (err) {
  641. t.ifError(err, 'Interval parse error');
  642. }
  643. t.end();
  644. });
  645. test('day of month and week are both set and dow is 7', function(t) {
  646. try {
  647. var interval = CronExpression.parse('10 2 12 8 7');
  648. t.ok(interval, 'Interval parsed');
  649. var next = interval.next();
  650. t.ok(next, 'Found next scheduled interval');
  651. t.ok(next.getDay() === 0 || next.getDate() === 12, 'Day or day of month matches');
  652. t.equal(next.getMonth(), 7, 'Month matches');
  653. next = interval.next();
  654. t.ok(next, 'Found next scheduled interval');
  655. t.ok(next.getDay() === 0 || next.getDate() === 12, 'Day or day of month matches');
  656. t.equal(next.getMonth(), 7, 'Month matches');
  657. next = interval.next();
  658. t.ok(next, 'Found next scheduled interval');
  659. t.ok(next.getDay() === 0 || next.getDate() === 12, 'Day or day of month matches');
  660. t.equal(next.getMonth(), 7, 'Month matches');
  661. next = interval.next();
  662. t.ok(next, 'Found next scheduled interval');
  663. t.ok(next.getDay() === 0 || next.getDate() === 12, 'Day or day of month matches');
  664. t.equal(next.getMonth(), 7, 'Month matches');
  665. } catch (err) {
  666. t.ifError(err, 'Interval parse error');
  667. }
  668. t.end();
  669. });
  670. test('day of month and week are both set and dow is 6,0', function(t) {
  671. try {
  672. var options = {
  673. currentDate: new CronDate('Wed, 26 Dec 2012 14:38:53')
  674. };
  675. var interval = CronExpression.parse('10 2 12 8 6,0', options);
  676. t.ok(interval, 'Interval parsed');
  677. var next = interval.next();
  678. t.ok(next, 'Found next scheduled interval');
  679. t.ok(next.getDay() === 6 || next.getDate() === 12, 'Day or day of month matches');
  680. t.equal(next.getMonth(), 7, 'Month matches');
  681. next = interval.next();
  682. t.ok(next, 'Found next scheduled interval');
  683. t.ok(next.getDay() === 0 || next.getDate() === 12, 'Day or day of month matches');
  684. t.equal(next.getMonth(), 7, 'Month matches');
  685. next = interval.next();
  686. t.ok(next, 'Found next scheduled interval');
  687. t.ok(next.getDay() === 6 || next.getDate() === 12, 'Day or day of month matches');
  688. t.equal(next.getMonth(), 7, 'Month matches');
  689. next = interval.next();
  690. t.ok(next, 'Found next scheduled interval');
  691. t.ok(next.getDay() === 0 || next.getDate() === 12, 'Day or day of month matches');
  692. t.equal(next.getMonth(), 7, 'Month matches');
  693. } catch (err) {
  694. t.ifError(err, 'Interval parse error');
  695. }
  696. t.end();
  697. });
  698. test('day of month and week are both set and dow is 6-7', function(t) {
  699. try {
  700. var options = {
  701. currentDate: new CronDate('Wed, 26 Dec 2012 14:38:53')
  702. };
  703. var interval = CronExpression.parse('10 2 12 8 6-7', options);
  704. t.ok(interval, 'Interval parsed');
  705. var next = interval.next();
  706. t.ok(next, 'Found next scheduled interval');
  707. t.ok(next.getDay() === 6 || next.getDate() === 12, 'Day or day of month matches');
  708. t.equal(next.getMonth(), 7, 'Month matches');
  709. next = interval.next();
  710. t.ok(next, 'Found next scheduled interval');
  711. t.ok(next.getDay() === 6 || next.getDate() === 12, 'Day or day of month matches');
  712. t.equal(next.getMonth(), 7, 'Month matches');
  713. next = interval.next();
  714. t.ok(next, 'Found next scheduled interval');
  715. t.ok(next.getDay() === 6 || next.getDate() === 12, 'Day or day of month matches');
  716. t.equal(next.getMonth(), 7, 'Month matches');
  717. // next = interval.next();
  718. t.ok(next, 'Found next scheduled interval');
  719. t.ok(next.getDay() === 6 || next.getDate() === 12, 'Day or day of month matches');
  720. t.equal(next.getMonth(), 7, 'Month matches');
  721. } catch (err) {
  722. t.ifError(err, 'Interval parse error');
  723. }
  724. t.end();
  725. });
  726. test('day of month validation should be ignored when day of month is wildcard and month is set', function (t) {
  727. try {
  728. var interval = CronExpression.parse('* * * * 2 *');
  729. t.ok(interval, 'Interval parsed');
  730. var next = interval.next();
  731. t.ok(next, 'Found next scheduled interval');
  732. t.equal(next.getHours(), 0, 'Hours matches');
  733. t.equal(next.getDate(), 1, 'Day of month matches');
  734. t.equal(next.getMonth() + 1, 2, 'Month matches');
  735. t.ok(next, 'Found next scheduled interval');
  736. } catch (err) {
  737. t.ifError(err, 'Interval parse error');
  738. }
  739. t.end();
  740. });
  741. test('day and date in week should matches', function(t){
  742. try {
  743. var interval = CronExpression.parse('0 1 1 1 * 1');
  744. t.ok(interval, 'Interval parsed');
  745. var next = interval.next();
  746. t.ok(next, 'Found next scheduled interval');
  747. t.equal(next.getHours(), 1, 'Hours matches');
  748. t.ok(next.getDay() === 1 || next.getDate() === 1, 'Day or day of month matches');
  749. next = interval.next();
  750. t.ok(next, 'Found next scheduled interval');
  751. t.equal(next.getHours(), 1, 'Hours matches');
  752. t.ok(next.getDay() === 1 || next.getDate() === 1, 'Day or day of month matches');
  753. next = interval.next();
  754. t.ok(next, 'Found next scheduled interval');
  755. t.equal(next.getHours(), 1, 'Hours matches');
  756. t.ok(next.getDay() === 1 || next.getDate() === 1, 'Day or day of month matches');
  757. } catch (err) {
  758. t.ifError(err, 'Interval parse error');
  759. }
  760. t.end();
  761. });
  762. test('should sort ranges and values in ascending order', function(t) {
  763. var options = {
  764. currentDate: new CronDate('Wed, 26 Dec 2012 14:38:53')
  765. };
  766. var interval = CronExpression.parse('0 12,13,10,1-3 * * *', options);
  767. t.ok(interval, 'Interval parsed');
  768. var hours = [ 1, 2, 3, 10, 12, 13 ];
  769. for (var i in hours) {
  770. next = interval.next();
  771. t.ok(next, 'Found next scheduled interval');
  772. t.equal(next.getHours(), hours[i], 'Hours matches');
  773. }
  774. t.end();
  775. });
  776. test('valid ES6 iterator should be returned if iterator options is set to true', function(t) {
  777. try {
  778. var options = {
  779. currentDate: new CronDate('Wed, 26 Dec 2012 14:38:53'),
  780. endDate: new CronDate('Wed, 26 Dec 2012 15:40:00'),
  781. iterator: true
  782. };
  783. var val = null;
  784. var interval = CronExpression.parse('*/25 * * * *', options);
  785. t.ok(interval, 'Interval parsed');
  786. val = interval.next();
  787. t.ok(val, 'Next iteration resolved');
  788. t.ok(val.value, 'Iterator value is set');
  789. t.notOk(val.done, 'Iterator is not finished');
  790. val = interval.next();
  791. t.ok(val, 'Next iteration resolved');
  792. t.ok(val.value, 'Iterator value is set');
  793. t.notOk(val.done, 'Iterator is not finished');
  794. val = interval.next();
  795. t.ok(val, 'Next iteration resolved');
  796. t.ok(val.value, 'Iterator value is set');
  797. t.ok(val.done, 'Iterator is finished');
  798. } catch (err) {
  799. t.ifError(err, 'Interval parse error');
  800. }
  801. t.end();
  802. });
  803. test('dow 6,7 6,0 0,6 7,6 should be equivalent', function(t) {
  804. try {
  805. var options = {
  806. currentDate: new CronDate('Wed, 26 Dec 2012 14:38:53'),
  807. };
  808. var expressions = [
  809. '30 16 * * 6,7',
  810. '30 16 * * 6,0',
  811. '30 16 * * 0,6',
  812. '30 16 * * 7,6'
  813. ];
  814. expressions.forEach(function(expression) {
  815. var interval = CronExpression.parse(expression, options);
  816. t.ok(interval, 'Interval parsed');
  817. var val = interval.next();
  818. t.equal(val.getDay(), 6, 'Day matches');
  819. val = interval.next();
  820. t.equal(val.getDay(), 0, 'Day matches');
  821. val = interval.next();
  822. t.equal(val.getDay(), 6, 'Day matches');
  823. });
  824. } catch (err) {
  825. t.ifError(err, 'Interval parse error');
  826. }
  827. t.end();
  828. });
  829. test('hour 0 9,11,1 * * * and 0 1,9,11 * * * should be equivalent', function(t) {
  830. try {
  831. var options = {
  832. currentDate: new CronDate('Wed, 26 Dec 2012 00:00:00'),
  833. };
  834. var expressions = [
  835. '0 9,11,1 * * *',
  836. '0 1,9,11 * * *'
  837. ];
  838. expressions.forEach(function(expression) {
  839. var interval = CronExpression.parse(expression, options);
  840. t.ok(interval, 'Interval parsed');
  841. var val = interval.next();
  842. t.equal(val.getHours(), 1, 'Hour matches');
  843. val = interval.next();
  844. t.equal(val.getHours(), 9, 'Hour matches');
  845. val = interval.next();
  846. t.equal(val.getHours(), 11, 'Hour matches');
  847. val = interval.next();
  848. t.equal(val.getHours(), 1, 'Hour matches');
  849. val = interval.next();
  850. t.equal(val.getHours(), 9, 'Hour matches');
  851. val = interval.next();
  852. t.equal(val.getHours(), 11, 'Hour matches');
  853. });
  854. } catch (err) {
  855. t.ifError(err, 'Interval parse error');
  856. }
  857. t.end();
  858. });
  859. test('it will work with #139 issue case', function(t) {
  860. var options = {
  861. currentDate : new Date('2018-11-15T16:15:33.522Z'),
  862. tz: 'Europe/Madrid'
  863. };
  864. var interval = CronExpression.parse('0 0 0 1,2 * *', options);
  865. var date = interval.next();
  866. t.equal(date.getFullYear(), 2018);
  867. t.equal(date.getDate(), 1);
  868. t.equal(date.getMonth(), 11);
  869. t.end();
  870. });
  871. test('should work for valid first/second/third/fourth/fifth occurence dayOfWeek (# char)', function(t) {
  872. try {
  873. var options = {
  874. currentDate: new CronDate('2019-04-30')
  875. };
  876. var expectedFirstDates = [
  877. new CronDate('2019-05-05'),
  878. new CronDate('2019-06-02'),
  879. new CronDate('2019-07-07'),
  880. new CronDate('2019-08-04')
  881. ];
  882. var expectedSecondDates = [
  883. new CronDate('2019-05-12'),
  884. new CronDate('2019-06-9'),
  885. new CronDate('2019-07-14'),
  886. new CronDate('2019-08-11')
  887. ];
  888. var expectedThirdDates = [
  889. new CronDate('2019-05-19'),
  890. new CronDate('2019-06-16'),
  891. new CronDate('2019-07-21'),
  892. new CronDate('2019-08-18')
  893. ];
  894. var expectedFourthDates = [
  895. new CronDate('2019-05-26'),
  896. new CronDate('2019-06-23'),
  897. new CronDate('2019-07-28'),
  898. new CronDate('2019-08-25')
  899. ];
  900. var expectedFifthDates = [
  901. new CronDate('2019-6-30'),
  902. new CronDate('2019-9-29'),
  903. new CronDate('2019-12-29'),
  904. new CronDate('2020-03-29')
  905. ];
  906. var allExpectedDates = [
  907. expectedFirstDates,
  908. expectedSecondDates,
  909. expectedThirdDates,
  910. expectedFourthDates,
  911. expectedFifthDates
  912. ];
  913. var expressions = [
  914. '0 0 0 ? * 0#1',
  915. '0 0 0 ? * 0#2',
  916. '0 0 0 ? * 0#3',
  917. '0 0 0 ? * 0#4',
  918. '0 0 0 ? * 0#5'
  919. ];
  920. expressions.forEach(function(expression, index) {
  921. var interval = CronExpression.parse(expression, options);
  922. var expectedDates = allExpectedDates[index];
  923. expectedDates.forEach(function(expected) {
  924. var date = interval.next();
  925. t.equal(
  926. date.toISOString(),
  927. expected.toISOString(),
  928. 'Expression "' + expression + '" has next() that matches expected: ' + expected.toISOString()
  929. );
  930. });
  931. expectedDates
  932. .slice(0, expectedDates.length - 1)
  933. .reverse()
  934. .forEach(function(expected) {
  935. var date = interval.prev();
  936. t.equal(
  937. date.toISOString(),
  938. expected.toISOString(),
  939. 'Expression "' + expression + '" has prev() that matches expected: ' + expected.toISOString()
  940. );
  941. });
  942. });
  943. } catch (err) {
  944. t.ifError(err, 'Interval parse error');
  945. }
  946. t.end();
  947. });
  948. test('should work for valid second sunday in may', function(t) {
  949. try {
  950. var options = {
  951. currentDate: new CronDate('2019-01-30')
  952. };
  953. var expectedDates = [
  954. new CronDate('2019-05-12'),
  955. new CronDate('2020-05-10'),
  956. new CronDate('2021-05-09'),
  957. new CronDate('2022-05-08')
  958. ];
  959. var interval = CronExpression.parse('0 0 0 ? MAY 0#2', options);
  960. expectedDates.forEach(function(expected) {
  961. var date = interval.next();
  962. t.equal(
  963. date.toISOString(),
  964. expected.toISOString(),
  965. 'Expression "0 0 0 ? MAY 0#2" has next() that matches expected: ' + expected.toISOString()
  966. );
  967. });
  968. expectedDates
  969. .slice(0, expectedDates.length - 1)
  970. .reverse()
  971. .forEach(function(expected) {
  972. var date = interval.prev();
  973. t.equal(
  974. date.toISOString(),
  975. expected.toISOString(),
  976. 'Expression "0 0 0 ? MAY 0#2" has prev() that matches expected: ' + expected.toISOString()
  977. );
  978. });
  979. } catch (err) {
  980. t.ifError(err, 'Interval parse error');
  981. }
  982. t.end();
  983. });
  984. test('should work for valid second sunday at noon in may', function(t) {
  985. try {
  986. var options = {
  987. currentDate: new CronDate('2019-05-12T11:59:00.000')
  988. };
  989. var expected = new CronDate('2019-05-12T12:00:00.000');
  990. var interval = CronExpression.parse('0 0 12 ? MAY 0#2', options);
  991. var date = interval.next();
  992. t.equal(
  993. date.toISOString(),
  994. expected.toISOString(),
  995. 'Expression "0 0 12 ? MAY 0#2" has next() that matches expected: ' + expected.toISOString()
  996. );
  997. } catch (err) {
  998. t.ifError(err, 'Interval parse error');
  999. }
  1000. t.end();
  1001. });
  1002. test('should work for valid second sunday at noon in may (UTC+3)', function(t) {
  1003. try {
  1004. var options = {
  1005. currentDate: new CronDate('2019-05-12T11:59:00.000', 'Europe/Sofia')
  1006. };
  1007. var expected = new CronDate('2019-05-12T12:00:00.000', 'Europe/Sofia');
  1008. var interval = CronExpression.parse('0 0 12 ? MAY 0#2', options);
  1009. var date = interval.next();
  1010. t.equal(
  1011. date.toISOString(),
  1012. expected.toISOString(),
  1013. 'Expression "0 0 12 ? MAY 0#2" has next() that matches expected: ' + expected.toISOString()
  1014. );
  1015. } catch (err) {
  1016. t.ifError(err, 'Interval parse error');
  1017. }
  1018. t.end();
  1019. });
  1020. test('should work with both dayOfMonth and nth occurence of dayOfWeek', function(t) {
  1021. try {
  1022. var options = {
  1023. currentDate: new CronDate('2019-04-01')
  1024. };
  1025. var expectedDates = [
  1026. new CronDate('2019-04-16'),
  1027. new CronDate('2019-04-17'),
  1028. new CronDate('2019-04-18'),
  1029. new CronDate('2019-05-15'),
  1030. new CronDate('2019-05-16'),
  1031. new CronDate('2019-05-18'),
  1032. ];
  1033. var interval = CronExpression.parse('0 0 0 16,18 * 3#3', options);
  1034. expectedDates.forEach(function(expected) {
  1035. var date = interval.next();
  1036. t.equal(
  1037. date.toISOString(),
  1038. expected.toISOString(),
  1039. 'Expression "0 0 0 16,18 * 3#3" has next() that matches expected: ' + expected.toISOString()
  1040. );
  1041. });
  1042. expectedDates
  1043. .slice(0, expectedDates.length - 1)
  1044. .reverse()
  1045. .forEach(function(expected) {
  1046. var date = interval.prev();
  1047. t.equal(
  1048. date.toISOString(),
  1049. expected.toISOString(),
  1050. 'Expression "0 0 0 16,18 * 3#3" has prev() that matches expected: ' + expected.toISOString()
  1051. );
  1052. });
  1053. } catch (err) {
  1054. t.ifError(err, 'Interval parse error');
  1055. }
  1056. t.end();
  1057. });
  1058. test('should error when passed invalid occurence value', function(t) {
  1059. var expressions = [
  1060. '0 0 0 ? * 1#',
  1061. '0 0 0 ? * 1#0',
  1062. '0 0 0 ? * 4#6',
  1063. '0 0 0 ? * 0##4',
  1064. ];
  1065. expressions.forEach(function(expression) {
  1066. t.throws(function() {
  1067. CronExpression.parse(expression);
  1068. }, new Error('Constraint error, invalid dayOfWeek occurrence number (#)'), expression);
  1069. });
  1070. t.end();
  1071. });
  1072. // The Quartz documentation says that if the # character is used then no other expression can be used in the dayOfWeek term: http://www.quartz-scheduler.org/api/2.3.0/index.html
  1073. test('cannot combine `-` range and # occurrence special characters', function(t) {
  1074. var expression = '0 0 0 ? * 2-4#2';
  1075. t.throws(function() {
  1076. CronExpression.parse(expression);
  1077. }, new Error('Constraint error, invalid dayOfWeek `#` and `-` special characters are incompatible'));
  1078. t.end();
  1079. });
  1080. test('cannot combine `/` repeat interval and # occurrence special characters', function(t) {
  1081. var expression = '0 0 0 ? * 1/2#3';
  1082. t.throws(function() {
  1083. CronExpression.parse(expression);
  1084. }, new Error('Constraint error, invalid dayOfWeek `#` and `/` special characters are incompatible'));
  1085. t.end();
  1086. });
  1087. test('cannot combine `,` list and # occurrence special characters', function(t) {
  1088. var expression = '0 0 0 ? * 0,6#4';
  1089. t.throws(function() {
  1090. CronExpression.parse(expression);
  1091. }, new Error('Constraint error, invalid dayOfWeek `#` and `,` special characters are incompatible'));
  1092. t.end();
  1093. });