-
Notifications
You must be signed in to change notification settings - Fork 653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(plugins/dates): support duration ranges #1137
Merged
spencermountain
merged 5 commits into
spencermountain:dev
from
Fdawgs:feat/duration-range
Aug 17, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8565e74
Merge pull request #1134 from spencermountain/dev
spencermountain 1351468
feat(plugins/dates): duration ranges
Fdawgs 2178719
fix(plugins/dates): make durations inclusive
Fdawgs fd45122
fix(plugins/dates): match `^in`
Fdawgs bade696
feat(plugins/dates): past duration ranges
Fdawgs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import test from 'tape' | ||
import nlp from './_lib.js' | ||
|
||
// Duration ranges | ||
const durArr = [ | ||
{ | ||
text: ['2 to 4 days', '2-4 days', 'two to four days'], | ||
duration: { years: 0, months: 0, days: 3, hours: 0, minutes: 0 }, | ||
}, | ||
{ | ||
text: ['1 to 2 weeks', '1-2 weeks', 'one to two weeks'], | ||
duration: { years: 0, months: 0, days: 14, hours: 0, minutes: 0 }, | ||
}, | ||
{ | ||
text: ['1 to 5 months', '1-5 months', 'one to five months'], | ||
duration: { years: 0, months: 5, days: 0, hours: 0, minutes: 0 }, | ||
}, | ||
{ | ||
text: ['2 to 4 years', '2-4 years', 'two to four years'], | ||
duration: { years: 3, months: 0, days: 0, hours: 0, minutes: 0 }, | ||
}, | ||
] | ||
|
||
const context = { | ||
today: '2024-01-01', | ||
} | ||
|
||
test('future duration-ranges', function (t) { | ||
durArr.forEach(obj => { | ||
obj.text.forEach(text => { | ||
const doc = nlp(`in ${text}`) | ||
const { duration, start, end } = doc.dates(context).get()[0] | ||
t.deepEqual(duration, obj.duration, text) | ||
t.ok(start > context.today, 'start date') | ||
t.ok(end > start, 'end date') | ||
}) | ||
}) | ||
t.end() | ||
}) | ||
|
||
test('past duration-ranges', function (t) { | ||
durArr.forEach(obj => { | ||
obj.text.forEach(text => { | ||
const doc = nlp(`${text} ago`) | ||
const { duration, start, end } = doc.dates(context).get()[0] | ||
t.deepEqual(duration, obj.duration, text) | ||
t.ok(start < context.today, 'start date') | ||
t.ok(end > start, 'end date') | ||
}) | ||
}) | ||
t.end() | ||
}) | ||
|
||
test('past duration-ranges', function (t) { | ||
durArr.forEach(obj => { | ||
obj.text.forEach(text => { | ||
const doc = nlp(`${text} ago`) | ||
const { duration, start, end } = doc.dates(context).get()[0] | ||
t.deepEqual(duration, obj.duration, text) | ||
t.ok(start < context.today, 'start date') | ||
t.ok(end > start, 'end date') | ||
}) | ||
}) | ||
t.end() | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully this is an okay way of doing this.
I found that days was projecting inclusively, but, other durations weren't.
For example
1-2 weeks
was returned as 8 days rather than 14 days.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks @spencermountain!
Hopefully last question, do i need to do anything extra for handling past tense in this?
I.e.
2 to 3 weeks ago
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, no problem - i would make a new section, in addition to this '2 to 4 weeks' one, with similar logic.
go for it!
oh, one thing - maybe add a
'^in'
on the match, so it doesn't interfere with2 to 3 weeks after june 3rd
etc.lookin good! thanks for the help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cheers @spencermountain, have added the
^in
as requested for the future tense match block.Struggling with the past tense, as you can see from the now failing tests! When you get a spare second could you take a look at the past tense block please? Thought it'd be as simple as flipping the logic.
If it's not a simple fix, happy to just tear out past tense support for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure - i can merge this to dev and fix the failing tests, if you're ready?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey Frazer, haven't forgotten about this - been really busy, then had covid. Will try to get to it shortly.
cheers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking this on @spencermountain, 42f9cd0 appears to have stopped the ranges from being inclusive?