Skip to content

Commit

Permalink
fix for ##1147
Browse files Browse the repository at this point in the history
  • Loading branch information
spencermountain committed Oct 2, 2024
1 parent dbb4e99 commit 982f350
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
44 changes: 43 additions & 1 deletion plugins/dates/src/api/parse/one/02-parse/05-explicit.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,47 @@ const parseExplicit = function (doc, context) {
}
}

// 'march 5th next year'
m = doc.match('[<month>#Month] [<date>#Value+]? of? the? [<rel>(this|next|last|current)] year')
if (m.found) {
let rel = m.groups('rel').text('reduced')
let year = impliedYear
if (rel === 'next') {
year += 1
} else if (rel === 'last') {
year -= 1
}
let obj = {
month: m.groups('month').text('reduced'),
date: m.groups('date').numbers(0).get()[0],
year,
}
let unit = new CalendarDate(obj, null, context)
if (unit.d.isValid() === true) {
return unit
}
}

// '5th of next month'
m = doc.match('^the? [<date>#Value+]? of? [<rel>(this|next|last|current)] month')
if (m.found) {
let month = context.today.month()
let rel = m.groups('rel').text('reduced')
if (rel === 'next') {
month += 1
} else if (rel === 'last') {
month -= 1
}
let obj = {
month,
date: m.groups('date').numbers(0).get()[0],
}
let unit = new CalendarDate(obj, null, context)
if (unit.d.isValid() === true) {
return unit
}
}

//no-years
// 'fifth of june'
m = doc.match('[<date>#Value] of? [<month>#Month]')
Expand All @@ -58,6 +99,7 @@ const parseExplicit = function (doc, context) {
return unit
}
}

// support 'december'
if (doc.has('#Month')) {
let obj = {
Expand All @@ -66,7 +108,7 @@ const parseExplicit = function (doc, context) {
year: context.today.year(),
}
let unit = new Month(obj, null, context)
// assume 'feb' in the future
// assume 'february' is always in the future
if (unit.d.month() < context.today.month()) {
obj.year += 1
unit = new Month(obj, null, context)
Expand Down
1 change: 1 addition & 0 deletions plugins/dates/src/api/parse/one/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +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(`\n==== '${parts.doc.text()}' =====`) // eslint-disable-line
Object.keys(parts).forEach(k => {
if (k !== 'doc' && parts[k]) {
Expand Down
2 changes: 2 additions & 0 deletions plugins/dates/src/compute/matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,5 +276,7 @@ let matches = [
{ match: '#Ordinal quarter of? #Year', unTag: 'Fraction' },
// a month from now
{ match: '(from|by|before) now', unTag: 'Time', tag: 'Date' },
// 18th next month
{ match: '#Value of? (this|next|last) #Date', tag: 'Date' },
]
export default matches
5 changes: 5 additions & 0 deletions plugins/dates/tests/startDates.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ const tests = [
tests: [
['october 10th this year', [2016, october, 10]],
['november 10th this year', [2016, november, 10]],
['november 10th next year', [2017, november, 10]],
['november 10th of last year', [2015, november, 10]],
['november 10th 2017', [2017, november, 10]],
['november 10th 2022', [2022, november, 10]],
['november 10th 1998', [1998, november, 10]],
Expand All @@ -551,6 +553,9 @@ const tests = [
// ['april fools next year', [2017, april, 1]],
// ['next year in june', [2017, june, 1]],
// ['next year after june', [2017, july, 1]],

['10th of next month', [2016, november, 10]],
['1st of the last month', [2016, september, 1]],
],
},
{
Expand Down

0 comments on commit 982f350

Please sign in to comment.