import test from 'tape' import nlp from './_lib.js' import spacetime from 'spacetime' test('week-logic', function (t) { const tests = [ { today: '2021-03-01', //on monday tests: [ ['monday', 'monday', 0], // today ['tuesday', 'tuesday', 1], ['wednesday', 'wednesday', 2], ['thursday', 'thursday', 3], ['friday', 'friday', 4], ['saturday', 'saturday', 5], ['sunday', 'sunday', 6], // 'this' ['this week', 'monday', 0], ['this monday', 'monday', 0], // today ['this tuesday', 'tuesday', 1], ['this wednesday', 'wednesday', 2], ['this thursday', 'thursday', 3], ['this friday', 'friday', 4], ['this weekend', 'saturday', 5], ['this saturday', 'saturday', 5], ['this sunday', 'sunday', 6], //'last' ['last week', 'monday', -7], ['last monday', 'monday', -7], ['last tuesday', 'tuesday', -6], ['last wednesday', 'wednesday', -5], ['last thursday', 'thursday', -4], ['last friday', 'friday', -3], ['last weekend', 'saturday', -2], ['last saturday', 'saturday', -2], ['last sunday', 'sunday', -1], // this past ['this past week', 'monday', -7], ['this past monday', 'monday', -7], ['this past tuesday', 'tuesday', -6], ['this past wednesday', 'wednesday', -5], ['this past thursday', 'thursday', -4], ['this past friday', 'friday', -3], ['this past weekend', 'saturday', -2], ['this past saturday', 'saturday', -2], ['this past sunday', 'sunday', -1], //'next' ['next week', 'monday', 7], ['next monday', 'monday', 7], ['next tuesday', 'tuesday', 8], ['next wednesday', 'wednesday', 9], ['next thursday', 'thursday', 10], ['next friday', 'friday', 11], ['next weekend', 'saturday', 12], ['next saturday', 'saturday', 12], ['next sunday', 'sunday', 13], ['mon', 'monday', 0], ['tue', 'tuesday', 1], ['tues', 'tuesday', 1], ['thu', 'thursday', 3], ['thurs', 'thursday', 3], ['fri', 'friday', 4], ['on monday', 'monday', 0], ['on tuesday', 'tuesday', 1], ['on wednesday', 'wednesday', 2], ['on thursday', 'thursday', 3], ['on friday', 'friday', 4], ['the monday', 'monday', 0], ['the tuesday', 'tuesday', 1], ['the wednesday', 'wednesday', 2], ['the thursday', 'thursday', 3], ['the friday', 'friday', 4], ['this coming monday', 'monday', 7], ['this coming tuesday', 'tuesday', 8], ['this coming wednesday', 'wednesday', 9], ['this coming thursday', 'thursday', 10], ['this coming friday', 'friday', 11], ['this coming saturday', 'saturday', 12], ['this coming sunday', 'sunday', 13], ['this upcoming monday', 'monday', 7], ['this upcoming tuesday', 'tuesday', 8], ['this upcoming wednesday', 'wednesday', 9], ['this upcoming thursday', 'thursday', 10], ['this upcoming friday', 'friday', 11], ['this upcoming saturday', 'saturday', 12], ['this upcoming sunday', 'sunday', 13], ['coming monday', 'monday', 7], ['coming friday', 'friday', 11], ['upcoming monday', 'monday', 7], ['upcoming friday', 'friday', 11], ['last mon', 'monday', -7], ['last tue', 'tuesday', -6], ['last tues', 'tuesday', -6], ['last thu', 'thursday', -4], ['last thurs', 'thursday', -4], ['last fri', 'friday', -3], ['next mon', 'monday', 7], ['next tue', 'tuesday', 8], ['next tues', 'tuesday', 8], ['next thu', 'thursday', 10], ['next thurs', 'thursday', 10], ['next fri', 'friday', 11], ['this past mon', 'monday', -7], ['this past tue', 'tuesday', -6], ['this past thu', 'thursday', -4], ['this past fri', 'friday', -3], ['monday morning', 'monday', 0], ['tuesday afternoon', 'tuesday', 1], ['wednesday evening', 'wednesday', 2], ['thursday night', 'thursday', 3], ['friday morning', 'friday', 4], ['saturday afternoon', 'saturday', 5], ['sunday evening', 'sunday', 6], ['next monday morning', 'monday', 7], ['next tuesday afternoon', 'tuesday', 8], ['next friday evening', 'friday', 11], ], }, { today: '2021-03-05', //on friday tests: [ ['monday', 'monday', 3], ['tuesday', 'tuesday', 4], ['wednesday', 'wednesday', 5], ['thursday', 'thursday', 6], ['friday', 'friday', 0], // today ['saturday', 'saturday', 1], ['sunday', 'sunday', 2], // 'this' ['this week', 'monday', -4], //backward ['this monday', 'monday', 3], ['this tuesday', 'tuesday', 4], ['this wednesday', 'wednesday', 5], ['this thursday', 'thursday', 6], ['this friday', 'friday', 0], // today ['this weekend', 'saturday', 1], ['this saturday', 'saturday', 1], ['this sunday', 'sunday', 2], //'last' ['last week', 'monday', -7 - 4], ['last monday', 'monday', -7 - 4], ['last tuesday', 'tuesday', -7 - 3], ['last wednesday', 'wednesday', -7 - 2], ['last thursday', 'thursday', -7 - 1], ['last friday', 'friday', -7], ['last weekend', 'saturday', -6], ['last saturday', 'saturday', -6], ['last sunday', 'sunday', -5], //'this past' ['this past week', 'monday', -7 - 4], ['this past monday', 'monday', -4], ['this past tuesday', 'tuesday', -3], ['this past wednesday', 'wednesday', -2], ['this past thursday', 'thursday', -1], ['this past friday', 'friday', -7], // ['this past weekend', 'saturday', -6], ['this past saturday', 'saturday', -6], ['this past sunday', 'sunday', -5], // //'next' ['next week', 'monday', 3], ['next monday', 'monday', 3], ['next tuesday', 'tuesday', 4], ['next wednesday', 'wednesday', 5], ['next thursday', 'thursday', 6], ['next friday', 'friday', 7], ['next weekend', 'saturday', 8], ['next saturday', 'saturday', 8], ['next sunday', 'sunday', 9], ['mon', 'monday', 3], ['tue', 'tuesday', 4], ['tues', 'tuesday', 4], ['thu', 'thursday', 6], ['thurs', 'thursday', 6], ['fri', 'friday', 0], ['on monday', 'monday', 3], ['on tuesday', 'tuesday', 4], ['on wednesday', 'wednesday', 5], ['on thursday', 'thursday', 6], ['on friday', 'friday', 0], ['the monday', 'monday', 3], ['the tuesday', 'tuesday', 4], ['the wednesday', 'wednesday', 5], ['the thursday', 'thursday', 6], ['the friday', 'friday', 0], ['this coming monday', 'monday', 3], ['this coming tuesday', 'tuesday', 4], ['this coming wednesday', 'wednesday', 5], ['this coming thursday', 'thursday', 6], ['this coming friday', 'friday', 7], ['this coming saturday', 'saturday', 8], ['this coming sunday', 'sunday', 9], ['this upcoming monday', 'monday', 3], ['this upcoming tuesday', 'tuesday', 4], ['this upcoming wednesday', 'wednesday', 5], ['this upcoming thursday', 'thursday', 6], ['this upcoming friday', 'friday', 7], ['this upcoming saturday', 'saturday', 8], ['this upcoming sunday', 'sunday', 9], ['coming monday', 'monday', 3], ['coming friday', 'friday', 7], ['upcoming monday', 'monday', 3], ['upcoming friday', 'friday', 7], ['last mon', 'monday', -11], ['last tue', 'tuesday', -10], ['last tues', 'tuesday', -10], ['last thu', 'thursday', -8], ['last thurs', 'thursday', -8], ['last fri', 'friday', -7], ['next mon', 'monday', 3], ['next tue', 'tuesday', 4], ['next tues', 'tuesday', 4], ['next thu', 'thursday', 6], ['next thurs', 'thursday', 6], ['next fri', 'friday', 7], ['this past mon', 'monday', -4], ['this past tue', 'tuesday', -3], ['this past thu', 'thursday', -1], ['this past fri', 'friday', -7], ['monday morning', 'monday', 3], ['tuesday afternoon', 'tuesday', 4], ['wednesday evening', 'wednesday', 5], ['thursday night', 'thursday', 6], ['friday morning', 'friday', 0], ['saturday afternoon', 'saturday', 1], ['sunday evening', 'sunday', 2], ['next monday morning', 'monday', 3], ['next tuesday afternoon', 'tuesday', 4], ['next friday evening', 'friday', 7], ], }, { today: '2021-03-03', //on wednesday tests: [ ['mon', 'monday', 5], ['tue', 'tuesday', 6], ['tues', 'tuesday', 6], ['thu', 'thursday', 1], ['thurs', 'thursday', 1], ['fri', 'friday', 2], ['on monday', 'monday', 5], ['on tuesday', 'tuesday', 6], ['on wednesday', 'wednesday', 0], ['on thursday', 'thursday', 1], ['on friday', 'friday', 2], ['the monday', 'monday', 5], ['the tuesday', 'tuesday', 6], ['the wednesday', 'wednesday', 0], ['the thursday', 'thursday', 1], ['the friday', 'friday', 2], ['this coming monday', 'monday', 5], ['this coming tuesday', 'tuesday', 6], ['this coming wednesday', 'wednesday', 7], ['this coming thursday', 'thursday', 8], ['this coming friday', 'friday', 9], ['this coming saturday', 'saturday', 10], ['this coming sunday', 'sunday', 11], ['this upcoming monday', 'monday', 5], ['this upcoming tuesday', 'tuesday', 6], ['this upcoming wednesday', 'wednesday', 7], ['this upcoming thursday', 'thursday', 8], ['this upcoming friday', 'friday', 9], ['this upcoming saturday', 'saturday', 10], ['this upcoming sunday', 'sunday', 11], ['coming monday', 'monday', 5], ['coming friday', 'friday', 9], ['upcoming monday', 'monday', 5], ['upcoming friday', 'friday', 9], ['last mon', 'monday', -9], ['last tue', 'tuesday', -8], ['last tues', 'tuesday', -8], ['last thu', 'thursday', -6], ['last thurs', 'thursday', -6], ['last fri', 'friday', -5], ['next mon', 'monday', 5], ['next tue', 'tuesday', 6], ['next tues', 'tuesday', 6], ['next thu', 'thursday', 8], ['next thurs', 'thursday', 8], ['next fri', 'friday', 9], ['this past mon', 'monday', -2], ['this past tue', 'tuesday', -1], ['this past thu', 'thursday', -6], ['this past fri', 'friday', -5], ['monday morning', 'monday', 5], ['tuesday afternoon', 'tuesday', 6], ['wednesday evening', 'wednesday', 0], ['thursday night', 'thursday', 1], ['friday morning', 'friday', 2], ['saturday afternoon', 'saturday', 3], ['sunday evening', 'sunday', 4], ['next monday morning', 'monday', 5], ['next tuesday afternoon', 'tuesday', 6], ['next friday evening', 'friday', 9], ], }, { today: '2021-03-07', //on sunday tests: [ ['mon', 'monday', 1], ['tue', 'tuesday', 2], ['tues', 'tuesday', 2], ['thu', 'thursday', 4], ['thurs', 'thursday', 4], ['fri', 'friday', 5], ['on monday', 'monday', 1], ['on tuesday', 'tuesday', 2], ['on wednesday', 'wednesday', 3], ['on thursday', 'thursday', 4], ['on friday', 'friday', 5], ['the monday', 'monday', 1], ['the tuesday', 'tuesday', 2], ['the wednesday', 'wednesday', 3], ['the thursday', 'thursday', 4], ['the friday', 'friday', 5], ['this coming monday', 'monday', 1], ['this coming tuesday', 'tuesday', 2], ['this coming wednesday', 'wednesday', 3], ['this coming thursday', 'thursday', 4], ['this coming friday', 'friday', 5], ['this coming saturday', 'saturday', 6], ['this coming sunday', 'sunday', 7], ['this upcoming monday', 'monday', 1], ['this upcoming tuesday', 'tuesday', 2], ['this upcoming wednesday', 'wednesday', 3], ['this upcoming thursday', 'thursday', 4], ['this upcoming friday', 'friday', 5], ['this upcoming saturday', 'saturday', 6], ['this upcoming sunday', 'sunday', 7], ['coming monday', 'monday', 1], ['coming friday', 'friday', 5], ['upcoming monday', 'monday', 1], ['upcoming friday', 'friday', 5], ['last mon', 'monday', -13], ['last tue', 'tuesday', -12], ['last tues', 'tuesday', -12], ['last thu', 'thursday', -10], ['last thurs', 'thursday', -10], ['last fri', 'friday', -9], ['next mon', 'monday', 1], ['next tue', 'tuesday', 2], ['next tues', 'tuesday', 2], ['next thu', 'thursday', 4], ['next thurs', 'thursday', 4], ['next fri', 'friday', 5], ['this past mon', 'monday', -6], ['this past tue', 'tuesday', -5], ['this past thu', 'thursday', -3], ['this past fri', 'friday', -2], ['monday morning', 'monday', 1], ['tuesday afternoon', 'tuesday', 2], ['wednesday evening', 'wednesday', 3], ['thursday night', 'thursday', 4], ['friday morning', 'friday', 5], ['saturday afternoon', 'saturday', 6], ['sunday evening', 'sunday', 0], ['next monday morning', 'monday', 1], ['next tuesday afternoon', 'tuesday', 2], ['next friday evening', 'friday', 5], ], }, { today: '2021-03-02', //on tuesday tests: [ ['mon', 'monday', 6], ['tue', 'tuesday', 0], ['tues', 'tuesday', 0], ['thu', 'thursday', 2], ['thurs', 'thursday', 2], ['fri', 'friday', 3], ['on monday', 'monday', 6], ['on tuesday', 'tuesday', 0], ['on wednesday', 'wednesday', 1], ['on thursday', 'thursday', 2], ['on friday', 'friday', 3], ['the monday', 'monday', 6], ['the tuesday', 'tuesday', 0], ['the wednesday', 'wednesday', 1], ['the thursday', 'thursday', 2], ['the friday', 'friday', 3], ['this coming monday', 'monday', 6], ['this coming tuesday', 'tuesday', 7], ['this coming wednesday', 'wednesday', 8], ['this coming thursday', 'thursday', 9], ['this coming friday', 'friday', 10], ['this coming saturday', 'saturday', 11], ['this coming sunday', 'sunday', 12], ['this upcoming monday', 'monday', 6], ['this upcoming tuesday', 'tuesday', 7], ['this upcoming wednesday', 'wednesday', 8], ['this upcoming thursday', 'thursday', 9], ['this upcoming friday', 'friday', 10], ['this upcoming saturday', 'saturday', 11], ['this upcoming sunday', 'sunday', 12], ['coming monday', 'monday', 6], ['coming friday', 'friday', 10], ['upcoming monday', 'monday', 6], ['upcoming friday', 'friday', 10], ['last mon', 'monday', -8], ['last tue', 'tuesday', -7], ['last tues', 'tuesday', -7], ['last thu', 'thursday', -5], ['last thurs', 'thursday', -5], ['last fri', 'friday', -4], ['next mon', 'monday', 6], ['next tue', 'tuesday', 7], ['next tues', 'tuesday', 7], ['next thu', 'thursday', 9], ['next thurs', 'thursday', 9], ['next fri', 'friday', 10], ['this past mon', 'monday', -1], ['this past tue', 'tuesday', -7], ['this past thu', 'thursday', -5], ['this past fri', 'friday', -4], ['monday morning', 'monday', 6], ['tuesday afternoon', 'tuesday', 0], ['wednesday evening', 'wednesday', 1], ['thursday night', 'thursday', 2], ['friday morning', 'friday', 3], ['saturday afternoon', 'saturday', 4], ['sunday evening', 'sunday', 5], ], }, ] tests.forEach((obj) => { const ctx = { today: obj.today } const today = spacetime(obj.today) obj.tests.forEach((a) => { const dates = nlp(a[0]).dates(ctx).get() t.equal(dates.length, 1, '[one date] ' + a[0]) const s = spacetime(dates[0].start) t.equal(s.format('day').toLowerCase(), a[1], '[day] ' + a[0]) // compare isos const want = today.add(a[2], 'day') t.equal(want.format('iso-short'), s.format('iso-short'), `[${a[2]} days] '${a[0]}'`) }) }) t.end() })