From 41c33f2db6f2d85511c0a407e52fb30d01705931 Mon Sep 17 00:00:00 2001 From: Eemeli Palotie Date: Fri, 1 Nov 2024 19:46:17 +0200 Subject: [PATCH] feat(nlp): better every day text for weekly frequency --- src/nlp/parsetext.ts | 19 +++++++++++++++++++ src/nlp/totext.ts | 8 +++++--- test/nlp.test.ts | 5 +++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/nlp/parsetext.ts b/src/nlp/parsetext.ts index fbaeccf9..0c75e9d2 100644 --- a/src/nlp/parsetext.ts +++ b/src/nlp/parsetext.ts @@ -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() diff --git a/src/nlp/totext.ts b/src/nlp/totext.ts index e77fd123..590c8193 100644 --- a/src/nlp/totext.ts +++ b/src/nlp/totext.ts @@ -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')) diff --git a/test/nlp.test.ts b/test/nlp.test.ts index 8948616c..667ccad9 100644 --- a/test/nlp.test.ts +++ b/test/nlp.test.ts @@ -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'], ['Every month', 'RRULE:FREQ=MONTHLY'], ['Every 6 months', 'RRULE:INTERVAL=6;FREQ=MONTHLY'], ['Every year', 'RRULE:FREQ=YEARLY'],