parser_day_of_month.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. var util = require('util');
  2. var test = require('tap').test;
  3. var CronParser = require('../lib/parser');
  4. test('parse cron with last day in a month', function(t) {
  5. var options = {
  6. currentDate: new Date(2014, 0, 1),
  7. endDate: new Date(2014, 10, 1)
  8. };
  9. try {
  10. var interval = CronParser.parseExpression('0 0 L * *', options);
  11. t.equal(interval.hasNext(), true);
  12. for (i = 0; i < 10; ++i) {
  13. var next = interval.next();
  14. t.ok(next, 'has a date');
  15. }
  16. } catch (err) {
  17. t.ifError(err, 'Parse read error');
  18. }
  19. t.end();
  20. });
  21. test('parse cron with last day in feb', function(t) {
  22. var options = {
  23. currentDate: new Date(2016, 0, 1),
  24. endDate: new Date(2016, 10, 1)
  25. };
  26. try {
  27. var interval = CronParser.parseExpression('0 0 6-20/2,L 2 *', options);
  28. t.equal(interval.hasNext(), true);
  29. var next = null;
  30. var items = 9;
  31. var i = 0;
  32. while(interval.hasNext()) {
  33. next = interval.next();
  34. i += 1;
  35. t.ok(next, 'has a date');
  36. }
  37. //leap year
  38. t.equal(next.getDate(), 29);
  39. t.equal(i, items);
  40. } catch (err) {
  41. t.ifError(err, 'Parse read error');
  42. }
  43. t.end();
  44. });
  45. test('parse cron with last day in feb', function(t) {
  46. var options = {
  47. currentDate: new Date(2014, 0, 1),
  48. endDate: new Date(2014, 10, 1)
  49. };
  50. try {
  51. var interval = CronParser.parseExpression('0 0 1,3,6-10,L 2 *', options);
  52. t.equal(interval.hasNext(), true);
  53. var next = null;
  54. while(interval.hasNext()) {
  55. next = interval.next();
  56. t.ok(next, 'has a date');
  57. }
  58. //common year
  59. t.equal(next.getDate(), 28);
  60. } catch (err) {
  61. t.ifError(err, 'Parse read error');
  62. }
  63. t.end();
  64. });