Skip to content

Commit

Permalink
feat(nlp): support weekly by hour texts (#590)
Browse files Browse the repository at this point in the history
* feat(nlp): support weekly by hour texts
 e.g. 'every week on Sunday at 10, 12 and 17' would serialize to
 'RRULE:FREQ=WEEKLY;BYDAY=SU;BYHOUR=10,12,17'

* after prettier

* forgot to add a case
  • Loading branch information
paviad authored Nov 10, 2023
1 parent 8713aa5 commit 62e7320
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/nlp/parsetext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,15 @@ export default function parseText(text: string, language: Language = ENGLISH) {
options.freq = RRule.WEEKLY
options.byweekday = [RRule.MO, RRule.TU, RRule.WE, RRule.TH, RRule.FR]
ttr.nextSymbol()
AT()
F()
break

case 'week(s)':
options.freq = RRule.WEEKLY
if (ttr.nextSymbol()) {
ON()
AT()
F()
}
break
Expand Down Expand Up @@ -198,6 +200,7 @@ export default function parseText(text: string, language: Language = ENGLISH) {
options.byweekday.push(RRule[wkd] as ByWeekday)
ttr.nextSymbol()
}
AT()
MDAYs()
F()
break
Expand Down
4 changes: 4 additions & 0 deletions src/nlp/totext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ export default class ToText {
} else if (this.byweekday) {
this._byweekday()
}

if (this.origOptions.byhour) {
this._byhour()
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions test/nlp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import { datetime } from './lib/utils'
const texts = [
['Every day', 'RRULE:FREQ=DAILY'],
['Every day at 10, 12 and 17', 'RRULE:FREQ=DAILY;BYHOUR=10,12,17'],
[
'Every week on Sunday at 10, 12 and 17',
'RRULE:FREQ=WEEKLY;BYDAY=SU;BYHOUR=10,12,17',
],
['Every week', 'RRULE:FREQ=WEEKLY'],
['Every hour', 'RRULE:FREQ=HOURLY'],
['Every 4 hours', 'RRULE:INTERVAL=4;FREQ=HOURLY'],
Expand Down

0 comments on commit 62e7320

Please sign in to comment.