Skip to content
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(nlp): better every day text for weekly frequency #643

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/nlp/parsetext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,25 @@ export default function parseText(text: string, language: Language = ENGLISH) {
const the = ttr.accept('the')
if (!(on || the)) return

const every = ttr.accept('every')

if (every) {
const day = ttr.accept('day(s)')
if (day) {
options.byweekday = [
RRule.MO,
RRule.TU,
RRule.WE,
RRule.TH,
RRule.FR,
RRule.SA,
RRule.SU,
]
}

return
}

do {
const nth = decodeNTH()
const wkd = decodeWKD()
Expand Down
8 changes: 5 additions & 3 deletions src/nlp/totext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,11 @@ export default class ToText {
this.add(gettext('on')).add(gettext('weekdays'))
}
} else if (this.byweekday && this.byweekday.isEveryDay) {
this.add(
this.plural(this.options.interval) ? gettext('days') : gettext('day')
)
if (this.plural(this.options.interval)) {
this.add(gettext('on')).add(gettext('every')).add(gettext('day'))
} else {
this.add(gettext('day'))
}
} else {
if (this.options.interval === 1) this.add(gettext('week'))

Expand Down
5 changes: 5 additions & 0 deletions test/nlp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ const texts = [
['Every week on Monday, Wednesday', 'RRULE:FREQ=WEEKLY;BYDAY=MO,WE'],
['Every weekday', 'RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR'],
['Every 2 weeks', 'RRULE:INTERVAL=2;FREQ=WEEKLY'],
[
'Every 2 weeks on every day',
'RRULE:INTERVAL=2;FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR,SA,SU',
],
['Every 2 weeks on Monday', 'RRULE:INTERVAL=2;FREQ=WEEKLY;BYDAY=MO'],
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verifies mostly that existing "Every X weeks on Y" didn't get broken

['Every month', 'RRULE:FREQ=MONTHLY'],
['Every 6 months', 'RRULE:INTERVAL=6;FREQ=MONTHLY'],
['Every year', 'RRULE:FREQ=YEARLY'],
Expand Down