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

222 lines
9.2 KiB
JavaScript

import test from 'tape'
import nlp from './_lib.js'
import spacetime from 'spacetime'
//single-date tests
//yep,
const january = 0
const february = 1
const march = 2
const april = 3
const may = 4
const june = 5
const july = 6
const august = 7
const september = 8
const october = 9
const november = 10
const december = 11
const tests = [
{
today: [2016, february, 11], //thursday
tests: [
['on october 2nd', [2016, october, 2]],
['on 2nd of march', [2016, march, 2]],
['on 2nd of march, 2016', [2016, march, 2]],
['on may 22nd', [2016, may, 22]],
['on tuesday march 22nd', [2016, march, 22]],
['on tuesday january 22nd, 2016', [2016, january, 22]],
['on 22 april 2016', [2016, april, 22]],
['on april 22nd', [2016, april, 22]],
['on 22nd of april', [2016, april, 22]],
['on the 22nd of april, 2016', [2016, april, 22]],
['on april 1st, 2016', [2016, april, 1]],
['on april 1st', [2016, april, 1]],
['on tuesday, april the 1st', [2016, april, 1]],
['on tuesday april 1st, 2016', [2016, april, 1]],
['on june 2nd', [2016, june, 2]],
['4:32 on march 2nd', [2016, march, 2]],
['at 2 oclock march 2nd', [2016, march, 2]],
// ['sometime tomorrow before 3', [2016, february, 12]],
['on 1999/12/25', [1999, december, 25]],
['on 4:23am july 5th ', [2016, july, 5]],
['@ 5pm march 2nd', [2016, march, 2]],
// ['on 5 pacific time march 2nd', [2016, march, 2]],
['around 1pm pacific time, july 5th', [2016, july, 5]],
// ['on the day after next', [2016, february, 13]],
// ['the last weekend in october', [2016, october, 30]],
// ['the last weekend this month', [2016, february, 27]],
['between monday and tuesday', [2016, february, 15]], //'exclusive' between
['on march 3rd', [2016, march, 3]],
['on 3rd of march', [2016, march, 3]],
['on march 3rd, 2016', [2016, march, 3]],
['on may 5th', [2016, may, 5]],
['on wednesday may 5th', [2016, may, 5]],
['on 5 may 2016', [2016, may, 5]],
['on may 5th, 2016', [2016, may, 5]],
['on 5th of may', [2016, may, 5]],
['on the 5th of may, 2016', [2016, may, 5]],
['on june 1st', [2016, june, 1]],
['on june 1st, 2016', [2016, june, 1]],
['on tuesday, june the 1st', [2016, june, 1]],
['on tuesday june 1st, 2016', [2016, june, 1]],
['on july 4th', [2016, july, 4]],
['on 4 july 2016', [2016, july, 4]],
['on july 4th, 2016', [2016, july, 4]],
['on 4th of july', [2016, july, 4]],
['on the 4th of july, 2016', [2016, july, 4]],
['on august 15th', [2016, august, 15]],
['on september 1st', [2016, september, 1]],
['on october 31st', [2016, october, 31]],
['on november 11th', [2016, november, 11]],
['on december 25th', [2016, december, 25]],
['on dec 25th', [2016, december, 25]],
['on 25 december 2016', [2016, december, 25]],
['on 2016-03-02', [2016, march, 2]],
['on 03/02/2016', [2016, march, 2]],
['on 2 Mar 2016', [2016, march, 2]],
['on march second', [2016, march, 2]],
['on 2pm march 2nd', [2016, march, 2]],
['on march 2nd at 2pm', [2016, march, 2]],
['on march 2nd @ 2pm', [2016, march, 2]],
['on @ march 2nd', [2016, march, 2]],
['on 4pm on march 2nd', [2016, march, 2]],
['on 4:32 on march 2nd', [2016, march, 2]],
['on 2 oclock march 2nd', [2016, march, 2]],
['on march 2nd 2 oclock', [2016, march, 2]],
['on 2 oclock july 5th', [2016, july, 5]],
['on july 5th 2pm PST', [2016, july, 5]],
['on 1pm pacific time, july 5th', [2016, july, 5]],
['on july 5th before noon pacific time', [2016, july, 5]],
['on july 5 2016 12 oclock PST', [2016, july, 5]],
['on new years eve', [2016, december, 31]],
['on april fools', [2016, april, 1]],
['on april fools, 2016', [2016, april, 1]],
['on halloween', [2016, october, 31]],
['on christmas', [2016, december, 25]],
['on valentines day', [2016, february, 14]],
['on independence day', [2016, july, 4]],
['on easter', [2016, march, 27]],
['on thanksgiving', [2016, november, 24]],
['on monday', [2016, february, 15]],
['on next monday', [2016, february, 15]],
['on this friday', [2016, february, 12]],
['on tomorrow', [2016, february, 12]],
['on yesterday', [2016, february, 10]],
['on today', [2016, february, 11]],
['on the 20th', [2016, february, 20]],
['on feb 20th', [2016, february, 20]],
['on 20th of february', [2016, february, 20]],
['on february 20th, 2016', [2016, february, 20]],
['around 2pm march 2nd', [2016, march, 2]],
['around noon on july 5th', [2016, july, 5]],
['at 2pm on march 2nd', [2016, march, 2]],
['at march 2nd 2pm', [2016, march, 2]],
['on around 1pm pacific time, july 5th', [2016, july, 5]],
['on st patricks day', [2016, march, 17]],
['on mothers day', [2016, may, 8]],
['on black friday', [2016, november, 25]],
['on next tuesday', [2016, february, 16]],
['on last friday', [2016, february, 5]],
['on this monday', [2016, february, 15]],
['on next wednesday', [2016, february, 17]],
['between tuesday and thursday', [2016, february, 10]],
],
},
{
today: [2016, february, 11],
tests: [
['before april the 22nd', [2016, april, 21]],
['by march 2nd 2 oclock', [2016, march, 1]],
['by august 2nd, 2016', [2016, august, 1]],
['by 22 november', [2016, november, 21]],
['by march 2nd at 2pm', [2016, march, 1]],
['before march 2nd at 2pm', [2016, march, 1]],
['before july 5th at 2pm', [2016, july, 4]],
['by july 5th, 2:12', [2016, july, 4]],
['by september 5th 2pm PST', [2016, september, 4]],
['by 1999-12-25', [1999, december, 24]],
['before 12/25/1999', [1999, december, 24]],
['by tomorrow', [2016, february, 11]],
['by april 22nd', [2016, april, 21]],
['by 22 april', [2016, april, 21]],
['by april 22nd, 2016', [2016, april, 21]],
['by 22nd of april', [2016, april, 21]],
['by the 22nd of april, 2016', [2016, april, 21]],
['by may 5th', [2016, may, 4]],
['by june 1st', [2016, may, 31]],
['by july 4th', [2016, july, 3]],
['by august 15th', [2016, august, 14]],
['by september 5th', [2016, september, 4]],
['by october 31st', [2016, october, 30]],
['by november 11th', [2016, november, 10]],
['by december 25th', [2016, december, 24]],
['by christmas', [2016, december, 24]],
['by halloween', [2016, october, 30]],
['by valentines day', [2016, february, 13]],
['by easter', [2016, march, 26]],
['by thanksgiving', [2016, november, 23]],
['by new years', [2016, december, 31]],
['by new years eve', [2016, december, 30]],
['by next monday', [2016, february, 14]],
['by this friday', [2016, february, 11]],
['by next week', [2016, february, 14]],
['by next month', [2016, february, 29]],
['by february 20th', [2016, february, 19]],
['by 4pm on march 2nd', [2016, march, 1]],
['by march 2nd @ 2pm', [2016, march, 1]],
['by 2016-03-02', [2016, march, 1]],
['by 03/02/2016', [2016, march, 1]],
['by 1999/12/25', [1999, december, 24]],
['by 12/25/1999', [1999, december, 24]],
['by 25-12-1999', [1999, december, 24]],
['before april 22nd', [2016, april, 21]],
['before may 5th', [2016, may, 4]],
['before june 1st', [2016, may, 31]],
['before july 4th', [2016, july, 3]],
['before august 15th', [2016, august, 14]],
['before september 5th', [2016, september, 4]],
['before october 31st', [2016, october, 30]],
['before christmas', [2016, december, 24]],
['before halloween', [2016, october, 30]],
['before valentines day', [2016, february, 13]],
['before easter', [2016, march, 26]],
['before thanksgiving', [2016, november, 23]],
['before new years', [2016, december, 31]],
['before next monday', [2016, february, 14]],
['before this friday', [2016, february, 11]],
['before 4pm on march 2nd', [2016, march, 1]],
['before 2016-03-02', [2016, march, 1]],
['before yesterday', [2016, february, 9]],
['before today', [2016, february, 10]],
['by st patricks day', [2016, march, 16]],
['by mothers day', [2016, may, 7]],
['by black friday', [2016, november, 24]],
['by independence day', [2016, july, 3]],
['by april fools', [2016, march, 31]],
['before march 2nd 2 oclock', [2016, march, 1]],
['before july 5th, 2:12', [2016, july, 4]],
['before 22 november', [2016, november, 21]],
['before 1999-12-25', [1999, december, 24]],
// ['by the day after tomorrow', [2016, february, 12]], //by
],
},
]
test('end dates', (t) => {
Object.keys(tests).forEach((k) => {
const context = {
today: tests[k].today,
timezone: 'Canada/Pacific',
}
const today = tests[k].today.join('-')
tests[k].tests.forEach((a) => {
const want = spacetime(a[1], context.timezone).endOf('day').iso()
const json = nlp(a[0]).dates(context).json()[0] || { dates: {} }
t.equal(json.dates.end, want, `[${today}] ${a[0]}`)
})
})
t.end()
})