Files
2026-07-13 12:48:55 +08:00

248 lines
6.8 KiB
JavaScript

import test from 'tape'
import nlp from './_lib.js'
// const relaxed = 14
const february = 1
//number of days between start+end
const tests = [
{
//for reference: https://calendar.google.com/calendar/render#main_7%7Cmonth-3+23617+23654+23617
today: [2016, february, 11],
tests: [
['today', 1],
['tomorrow', 1],
['next week', 7],
['sometime next week', 7],
['on october 22nd', 1],
['on feb 22 2019', 1],
['july 3rd', 1],
['2/12/2018', 1],
['on 22/2/2016', 1],
['before tomorrow', 1],
// ['next month', 31], //march
// ['this march', 31],
// ['this september', 30],
// ['next march', 31],
// ['in july', 31],
// ['next february', 28],
['february 12th', 1],
//'by' includes today
['by february 12th', 1],
['by february 21', 10],
['before february 22', 11],
['before march', 19],
['on february 22', 1],
['between monday and tuesday', 1],
['between monday and wednesday', 2],
// ['tuesday and wednesday next week', 2],
// ['march and april 2022', 61],
['first week of september', 7],
['second week of october', 7],
['third week of june', 7],
['fourth week of july', 7],
['last week of july', 7],
['yesterday', 1],
['day after tomorrow', 1],
['day before yesterday', 1],
['this week', 7],
['last week', 7],
['this weekend', 2],
['next weekend', 2],
['next monday', 1],
['next tuesday', 1],
['next wednesday', 1],
['next thursday', 1],
['next friday', 1],
['next saturday', 1],
['next sunday', 1],
['last monday', 1],
['last tuesday', 1],
['last wednesday', 1],
['last thursday', 1],
['last friday', 1],
['last saturday', 1],
['last sunday', 1],
['this monday', 1],
['this tuesday', 1],
['this wednesday', 1],
['this thursday', 1],
['this friday', 1],
['this saturday', 1],
['this sunday', 1],
['monday', 1],
['tuesday', 1],
['wednesday', 1],
['thursday', 1],
['friday', 1],
['saturday', 1],
['sunday', 1],
['on monday', 1],
['on tuesday', 1],
['on wednesday', 1],
['on thursday', 1],
['on friday', 1],
['on saturday', 1],
['on sunday', 1],
['february 11th', 1],
['february 11', 1],
['feb 11', 1],
['feb 11th', 1],
['february 12', 1],
['february 13', 1],
['february 14', 1],
['february 15', 1],
['february 20', 1],
['february 21', 1],
['february 22', 1],
['february 28', 1],
['february 29', 1],
['march 1', 1],
['march 1st', 1],
['march 15', 1],
['march 31', 1],
['january 1', 1],
['january 31', 1],
['december 25', 1],
['december 31', 1],
['on march 1', 1],
['on march 15', 1],
['on january 5', 1],
['by march 1', 19],
['by march 15', 4],
['by april 1', 21],
['before march 1', 19],
['before april 1', 21],
['before may 1', 20],
['after february 11', 0],
['after tomorrow', 0],
['after monday', 0],
['until february 20', 9],
['until march 1', 19],
['until friday', 1],
['through february 20', 1],
['through march 1', 1],
['from monday to tuesday', 2],
['from monday to wednesday', 3],
['from monday to friday', 5],
['from tuesday to thursday', 3],
['from wednesday to friday', 3],
['monday to tuesday', 2],
['monday to wednesday', 3],
['monday to friday', 5],
['tuesday to wednesday', 2],
['wednesday to friday', 3],
['between tuesday and thursday', -5],
['between friday and sunday', 2],
['between monday and friday', -3],
['between wednesday and saturday', -4],
['first week of february', 7],
['second week of february', 7],
['third week of february', 7],
['fourth week of february', 7],
['last week of february', 7],
['first week of march', 7],
['last week of march', 7],
['first week of january', 7],
['second week of april', 7],
['third week of may', 7],
['fourth week of december', 7],
['last week of december', 7],
['week of february 15', 1],
['week of march 1', 1],
['in 3 days', 1],
['in 5 days', 1],
['in 10 days', 1],
['in 2 weeks', 1],
['3 days ago', 1],
['5 days ago', 1],
['2 weeks ago', 1],
['next month', 0],
['last month', 0],
['this month', 0],
['february', 0],
['march', 0],
['this february', 0],
['this march', 0],
['next february', 0],
['next march', 0],
['in february', 0],
['in march', 0],
['in july', 0],
['in september', 0],
['q1 2016', 0],
['q2 2016', 0],
['q3 2016', 0],
['q4 2016', 0],
['first quarter 2016', 0],
['second quarter 2016', 0],
['january 2016', 0],
['february 2016', 0],
['march 2016', 0],
['2016', 0],
['2017', 0],
['in 2017', 0],
['spring 2016', 0],
['summer 2016', 0],
['fall 2016', 0],
['winter 2016', 0],
['christmas 2016', 1],
['thanksgiving 2016', 1],
['easter 2016', 1],
['first day of february', 1],
['last day of february', 1],
['first day of march', 1],
['last day of march', 1],
['5th day of february', 1],
['10th day of february', 1],
['on 2/11/2016', 1],
['2/11/2016', 1],
['11/2/2016', 1],
['2016-02-11', 1],
['on 12/25/2016', 1],
['12/25/2016', 1],
['25/12/2016', 1],
['october 22', 1],
['october 22nd', 1],
['on october 22', 1],
['june 1st', 1],
['june 30th', 1],
['july 4th', 1],
['by next monday', 4],
['by next friday', 8],
['before next monday', 4],
['sometime this week', 7],
['sometime next month', 0],
['end of february', 0],
['end of march', 0],
['beginning of march', 0],
['mid february', 0],
['february and march', 0],
['march and april', 0],
['monday and tuesday', 1],
['tuesday and wednesday next week', 1],
['monday through wednesday', 3],
['tuesday through friday', 4],
['this coming weekend', 2],
// ['after july', relaxed],
// ['after september 4rth 2016', relaxed],
],
},
]
test('day durations', t => {
tests.forEach(obj => {
const context = {
today: obj.today,
}
const today = obj.today.join('-')
obj.tests.forEach(a => {
const json = nlp(a[0]).dates(context).json()[0] || { dates: {} }
const duration = json.dates.duration || {}
t.equal(duration.days, a[1], `[${today}] ${a[0]}`)
})
})
t.end()
})