90 lines
6.6 KiB
JavaScript
90 lines
6.6 KiB
JavaScript
import test from 'tape'
|
|
import nlp from './_lib.js'
|
|
|
|
test('full iso start+end tests', function (t) {
|
|
const context = {
|
|
timezone: 'Asia/Shanghai',
|
|
today: '2021-02-19', //friday
|
|
dayStart: '8:00am',
|
|
dayEnd: '8:00pm',
|
|
}
|
|
const arr = [
|
|
['monday', '2021-02-22T08:00:00.000+08:00', '2021-02-22T20:00:00.000+08:00'],
|
|
['monday at 3pm', '2021-02-22T15:00:00.000+08:00', '2021-02-22T20:00:00.000+08:00'],
|
|
['monday 3pm to 5pm', '2021-02-22T15:00:00.000+08:00', '2021-02-22T17:00:00.000+08:00'],
|
|
['9am to 5pm', '2021-02-19T09:00:00.000+08:00', '2021-02-19T17:00:00.000+08:00'],
|
|
['9am to 5pm feb 26th', '2021-02-26T09:00:00.000+08:00', '2021-02-26T17:00:00.000+08:00'],
|
|
['9am to 5am', '2021-02-19T05:00:00.000+08:00', '2021-02-19T09:00:00.000+08:00'],
|
|
['4pm sharp on tuesday', '2021-02-23T16:00:00.000+08:00', '2021-02-23T20:00:00.000+08:00'],
|
|
['tuesday 4pm sharp', '2021-02-23T16:00:00.000+08:00', '2021-02-23T20:00:00.000+08:00'],
|
|
['tuesday 3:30 on the dot', '2021-02-23T15:30:00.000+08:00', '2021-02-23T20:00:00.000+08:00'],
|
|
['3-4 on tuesday', '2021-02-23T15:00:00.000+08:00', '2021-02-23T16:00:00.000+08:00'],
|
|
['3-5 on tues june 1st', '2021-06-01T15:00:00.000+08:00', '2021-06-01T17:00:00.000+08:00'],
|
|
['3-5 on june 1st', '2021-06-01T15:00:00.000+08:00', '2021-06-01T17:00:00.000+08:00'],
|
|
['3-4pm', '2021-02-19T15:00:00.000+08:00', '2021-02-19T16:00:00.000+08:00'],
|
|
// ['4pm-5', '2021-02-19T16:00:00.000+08:00', '2021-02-19T17:00:00.000+08:00'],
|
|
['wednesday', '2021-02-24T08:00:00.000+08:00', '2021-02-24T20:00:00.000+08:00'],
|
|
['tomorrow', '2021-02-20T08:00:00.000+08:00', '2021-02-20T20:00:00.000+08:00'],
|
|
['today', '2021-02-19T08:00:00.000+08:00', '2021-02-19T20:00:00.000+08:00'],
|
|
['friday at 10am', '2021-02-19T10:00:00.000+08:00', '2021-02-19T20:00:00.000+08:00'],
|
|
['friday 10am to 12pm', '2021-02-19T10:00:00.000+08:00', '2021-02-19T12:00:00.000+08:00'],
|
|
['between 10am and 12pm friday', '2021-02-19T10:00:00.000+08:00', '2021-02-19T12:00:00.000+08:00'],
|
|
['wednesday from 2 to 4pm', '2021-02-24T14:00:00.000+08:00', '2021-02-24T16:00:00.000+08:00'],
|
|
['2-4pm on wednesday', '2021-02-24T14:00:00.000+08:00', '2021-02-24T16:00:00.000+08:00'],
|
|
['2pm-4pm', '2021-02-19T14:00:00.000+08:00', '2021-02-19T16:00:00.000+08:00'],
|
|
['2pm to 4pm tomorrow', '2021-02-20T14:00:00.000+08:00', '2021-02-20T16:00:00.000+08:00'],
|
|
['9-5 tomorrow', '2021-02-20T09:00:00.000+08:00', '2021-02-20T17:00:00.000+08:00'],
|
|
['9am-5pm tomorrow', '2021-02-20T09:00:00.000+08:00', '2021-02-20T17:00:00.000+08:00'],
|
|
['tomorrow at 3pm', '2021-02-20T15:00:00.000+08:00', '2021-02-20T20:00:00.000+08:00'],
|
|
['noon tomorrow', '2021-02-20T12:00:00.000+08:00', '2021-02-20T20:00:00.000+08:00'],
|
|
['tonight at 8pm', '2021-02-19T20:00:00.000+08:00', '2021-02-19T20:00:00.000+08:00'],
|
|
['8pm tonight', '2021-02-19T20:00:00.000+08:00', '2021-02-19T20:00:00.000+08:00'],
|
|
['this weekend', '2021-02-20T08:00:00.000+08:00', '2021-02-21T20:00:00.000+08:00'],
|
|
['last friday', '2021-02-12T08:00:00.000+08:00', '2021-02-12T20:00:00.000+08:00'],
|
|
['feb 22nd at 9am', '2021-02-22T09:00:00.000+08:00', '2021-02-22T20:00:00.000+08:00'],
|
|
['9am feb 22nd', '2021-02-22T09:00:00.000+08:00', '2021-02-22T20:00:00.000+08:00'],
|
|
['march 1st 9am to 5pm', '2021-03-01T09:00:00.000+08:00', '2021-03-01T17:00:00.000+08:00'],
|
|
['between 9am and 5pm march 1st', '2021-03-01T09:00:00.000+08:00', '2021-03-01T17:00:00.000+08:00'],
|
|
['tuesday 9-11', '2021-02-23T09:00:00.000+08:00', '2021-02-23T11:00:00.000+08:00'],
|
|
['tuesday 10:30am', '2021-02-23T10:30:00.000+08:00', '2021-02-23T20:00:00.000+08:00'],
|
|
['half past 3 tuesday', '2021-02-23T15:30:00.000+08:00', '2021-02-23T20:00:00.000+08:00'],
|
|
['saturday 6pm on the dot', '2021-02-20T18:00:00.000+08:00', '2021-02-20T20:00:00.000+08:00'],
|
|
['11am to 1pm', '2021-02-19T11:00:00.000+08:00', '2021-02-19T13:00:00.000+08:00'],
|
|
['11am-1pm', '2021-02-19T11:00:00.000+08:00', '2021-02-19T13:00:00.000+08:00'],
|
|
['10pm to 2am', '2021-02-19T02:00:00.000+08:00', '2021-02-19T22:00:00.000+08:00'],
|
|
['10pm-2am', '2021-02-19T02:00:00.000+08:00', '2021-02-19T22:00:00.000+08:00'],
|
|
['monday 9 to 5', '2021-02-22T09:00:00.000+08:00', '2021-02-22T17:00:00.000+08:00'],
|
|
['from 9am to 5pm monday', '2021-02-22T09:00:00.000+08:00', '2021-02-22T17:00:00.000+08:00'],
|
|
['between 2pm and 4pm tuesday', '2021-02-23T14:00:00.000+08:00', '2021-02-23T16:00:00.000+08:00'],
|
|
['tuesday between 2 and 4', '2021-02-23T14:00:00.000+08:00', '2021-02-23T16:00:00.000+08:00'],
|
|
['june 1st 3pm-5pm', '2021-06-01T15:00:00.000+08:00', '2021-06-01T17:00:00.000+08:00'],
|
|
['3pm-5pm june 1st', '2021-06-01T15:00:00.000+08:00', '2021-06-01T17:00:00.000+08:00'],
|
|
['4-5pm', '2021-02-19T16:00:00.000+08:00', '2021-02-19T17:00:00.000+08:00'],
|
|
['4pm-5pm', '2021-02-19T16:00:00.000+08:00', '2021-02-19T17:00:00.000+08:00'],
|
|
['4pm-5pm on tuesday', '2021-02-23T16:00:00.000+08:00', '2021-02-23T17:00:00.000+08:00'],
|
|
['tues at 3pm to 5pm', '2021-02-23T15:00:00.000+08:00', '2021-02-23T17:00:00.000+08:00'],
|
|
['wed between 2 - 5pm', '2021-02-24T14:00:00.000+08:00', '2021-02-24T17:00:00.000+08:00'],
|
|
['june 4 at 2pm - 9pm', '2021-06-04T14:00:00.000+08:00', '2021-06-04T21:00:00.000+08:00'],
|
|
['tomorrow before noon', '2021-02-20T08:00:00.000+08:00', '2021-02-20T12:00:00.000+08:00'],
|
|
['in 48 hours', '2021-02-21T08:00:00.000+08:00', '2021-02-21T20:00:00.000+08:00'],
|
|
['next week', '2021-02-22T08:00:00.000+08:00', '2021-02-28T20:00:00.000+08:00'],
|
|
['christmas', '2021-12-25T08:00:00.000+08:00', '2021-12-25T20:00:00.000+08:00'],
|
|
['christmas 9am to 5pm', '2021-12-25T09:00:00.000+08:00', '2021-12-25T17:00:00.000+08:00'],
|
|
['new years eve 8pm', '2021-12-31T20:00:00.000+08:00', '2021-12-31T20:00:00.000+08:00'],
|
|
['halloween at 7pm', '2021-10-31T19:00:00.000+08:00', '2021-10-31T20:00:00.000+08:00'],
|
|
['easter monday 10am', '2021-04-05T10:00:00.000+08:00', '2021-04-05T20:00:00.000+08:00'],
|
|
['q1 2021', '2021-01-01T08:00:00.000+08:00', '2021-03-31T20:00:00.000+08:00'],
|
|
['spring 2021', '2021-03-01T08:00:00.000+08:00', '2021-04-30T20:00:00.000+08:00'],
|
|
['on the 20th', '2021-02-20T08:00:00.000+08:00', '2021-02-20T20:00:00.000+08:00'],
|
|
['feb 20th', '2021-02-20T08:00:00.000+08:00', '2021-02-20T20:00:00.000+08:00'],
|
|
['20th of february', '2021-02-20T08:00:00.000+08:00', '2021-02-20T20:00:00.000+08:00'],
|
|
]
|
|
arr.forEach((a) => {
|
|
const doc = nlp(a[0])
|
|
const dates = doc.dates(context).get()[0] || {}
|
|
t.equal(dates.start, a[1], '[start] ' + a[0])
|
|
t.equal(dates.end, a[2], '[end] ' + a[0])
|
|
})
|
|
t.end()
|
|
})
|