diff --git a/src/operations/calendar-round-wildcard.js b/src/operations/calendar-round-wildcard.js index 4bf9c0e..33ff7a1 100644 --- a/src/operations/calendar-round-wildcard.js +++ b/src/operations/calendar-round-wildcard.js @@ -1,33 +1,5 @@ const CalendarRound = require('../cr/calendar-round') -const wildcard = require('../wildcard') - -class CalendarRoundWildcard { - /** - * @param {CalendarRound} cr - */ - constructor (cr) { - this.cr = cr - this.start_date = new CalendarRound( - 4, 'Ajaw', - 8, 'Kumk\'u', - ) - } - - run () { - let potentials = [] - // Iterate through dates and compare - let iter = new CalendarRoundIterator() - let cr = iter.next() - while (!cr.done) { - if (this.cr.match(cr.value)) { - potentials.push(cr.value) - } - cr = iter.next() - } - return potentials - } - -} +const origin = require('../cr/index').origin class CalendarRoundIterator { /** @@ -36,12 +8,13 @@ class CalendarRoundIterator { */ constructor (date) { if (date === undefined) { - date = new CalendarRound( - 4, 'Ajaw', - 8, 'Kumk\'u', - ) + date = origin } this.date = date + this.reset() + } + + reset () { this.current = this.date this.is_first = true } @@ -63,4 +36,30 @@ class CalendarRoundIterator { } +const iter = new CalendarRoundIterator() + +class CalendarRoundWildcard { + /** + * @param {CalendarRound} cr + */ + constructor (cr) { + this.cr = cr + } + + run () { + let potentials = [] + // Iterate through dates and compare + let cr = iter.next() + while (!cr.done) { + if (this.cr.match(cr.value)) { + potentials.push(cr.value) + } + cr = iter.next() + } + iter.reset() + return potentials + } + +} + module.exports = CalendarRoundWildcard