From e7c792450e2b887d7685f9fc91b2799fa023ebe5 Mon Sep 17 00:00:00 2001 From: Shaun Hurley Date: Tue, 15 Mar 2022 13:35:30 -0400 Subject: [PATCH] test: test case demonstrating .next() issue on composite schedules --- test/issues/occurences-next-test.js | 46 +++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test/issues/occurences-next-test.js diff --git a/test/issues/occurences-next-test.js b/test/issues/occurences-next-test.js new file mode 100644 index 0000000..6d0f8ac --- /dev/null +++ b/test/issues/occurences-next-test.js @@ -0,0 +1,46 @@ +const later = require('../..'); +const { schedule } = later; +const should = require('should'); + +describe('Schedule', function () { + later.date.UTC(); + + describe('next', function () { + const d = new Date('2021-01-01T00:00:00Z'); + const e = new Date('2016-01-01T00:00:00Z'); + + it('should return next three (3) valid dates from a composite schedule', function () { + const s = { + schedules: [ + { s: [0], m: [30], h: [18], D: [1], M: [2] }, + { s: [0], m: [30], h: [17], D: [2], M: [2], Y: [2023] } + ], + exceptions: [] + }; + schedule(s) + .next(3) + .should.eql([ + new Date('2023-02-01T18:30:00Z'), + new Date('2023-02-02T17:30:00Z'), + new Date('2024-02-01T18:30:00Z') + ]); + }); + + it('should return next three (3) valid dates from a composite schedule', function () { + const s = { + schedules: [ + { s: [0], m: [30], h: [17], D: [2], M: [2], Y: [2021] }, + { s: [0], m: [30], h: [18], D: [1], M: [1] } + ], + exceptions: [] + }; + schedule(s) + .next(3) + .should.eql([ + new Date('2023-02-01T18:30:00Z'), + new Date('2023-02-02T17:30:00Z'), + new Date('2024-02-01T18:30:00Z') + ]); + }); + }); +});