Skip to content

Commit

Permalink
fix between month-month template
Browse files Browse the repository at this point in the history
  • Loading branch information
spencermountain committed Oct 6, 2024
1 parent 3b40748 commit 230ef27
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 20 deletions.
23 changes: 12 additions & 11 deletions plugins/dates/scratch.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,20 @@ txt = `5th day of q1 2002`
// txt = 'on april 22nd'
txt = 'in basically one week from now'
txt = 'go shopping with april'
txt = 'between Sept and Oct 2008'
txt = 'only in 2018 and 2020'
txt = '2024/02/05 and 2024/03/09'
txt = 'in 03/28'
txt = 'in 28/28'
txt = '1 to 5 weeks ago'
txt = 'in 2-4 years from now'
txt = 'in 1-2 weeks from now'
txt = 'in 1 to 2 months'
txt = `end of september`
txt = 'between Oct and Sept 2008'
// txt = 'sept 2008 to oct 2008'
// txt = 'only in 2018 and 2020'
// txt = '2024/02/05 and 2024/03/09'
// txt = 'in 03/28'
// txt = 'in 28/28'
// txt = '1 to 5 weeks ago'
// txt = 'in 2-4 years from now'
// txt = 'in 1-2 weeks from now'
// txt = 'in 1 to 2 months'
// txt = `end of september`

// nlp.verbose('tagger')
let doc = nlp(txt).debug()
let doc = nlp(txt)
// doc.debug('dates')
// console.log(doc.dates().get())
// doc.times().format('24h')
Expand Down
4 changes: 0 additions & 4 deletions plugins/dates/src/api/find/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import split from './split.js'

const findDate = function (doc) {
// if (doc.world.isVerbose() === 'date') {
// doc.debug()
// console.log(' ---')
// }
let dates = doc.match('#Date+')
// ignore only-durations like '20 minutes'
dates = dates.filter(m => {
Expand Down
2 changes: 1 addition & 1 deletion plugins/dates/src/api/parse/one/01-tokenize/03-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const parseTime = function (doc, context) {
time = time.not('^(at|by|for|before|this|after)')
time = time.not('sharp')
time = time.not('on the dot')
// time.debug()

let s = spacetime.now(context.timezone)
let now = s.clone()
// check for known-times (like 'today')
Expand Down
2 changes: 1 addition & 1 deletion plugins/dates/src/api/parse/one/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import transform from './03-transform/index.js'
const env = typeof process === 'undefined' || !process.env ? self.env || {} : process.env
const log = parts => {
if (env.DEBUG_DATE) {
console.log(parts)
// console.log(parts)// eslint-disable-line
console.log(`\n==== '${parts.doc.text()}' =====`) // eslint-disable-line
Object.keys(parts).forEach(k => {
if (k !== 'doc' && parts[k]) {
Expand Down
29 changes: 27 additions & 2 deletions plugins/dates/src/api/parse/range/02-date-range.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
import parseDate from '../one/index.js'
import reverseMaybe from './_reverse.js'
import Unit from '../one/units/Unit.js'
import { Year, Month, CalendarDate } from '../one/units/index.js'
import { Month, CalendarDate } from '../one/units/index.js'

export default [


{
// month-ranges have some folksy rules
match: 'between [<start>#Month] and [<end>#Month] [<year>#Year?]',
desc: 'between march and jan',
parse: (m, context) => {
let { start, end, year } = m.groups()
let y = year && year.found ? Number(year.text('reduced')) : context.today.year()
let obj = { month: start.text('reduced'), year: y }
let left = new Month(obj, null, context).start()
obj = { month: end.text('reduced'), year: y }
let right = new Month(obj, null, context).start()
if (left.d.isAfter(right.d)) {
return {
start: right,
end: left,
}
}
return {
start: left,
end: right,
}
},
},

{
// two explicit dates - 'between friday and sunday'
match: 'between [<start>.+] and [<end>.+]',
Expand Down
2 changes: 1 addition & 1 deletion plugins/dates/tests/day-start.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let arr = [
'in august',
'tomorrow',
'q2 1999',
'between june and july',
// 'between june and july',
'between tuesday and wednesday',
'june 2nd to 5th 2020',
'the 5th of august',
Expand Down
4 changes: 4 additions & 0 deletions plugins/dates/tests/equals.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ const arr = [
['until feb 3 2024', '2020-01-21 to 2024-02-03'],
['first half of march', '2020-03-01 to 2020-03-16'],
['second half of march', '2020-03-16 to 2020-03-30 '],
['between Sept and Oct', 'sept 2020 to oct 2020'],
['between Sept and Oct 2008', 'sept 2008 to oct 2008'],
['between Oct and Sept', 'sept 2020 to oct 2020'],
['between Oct and Sept 2008', 'sept 2008 to oct 2008']
]

test('date-variety', function (t) {
Expand Down

0 comments on commit 230ef27

Please sign in to comment.