From a158b10c00d14f781b955a77f7d89edf3cc73005 Mon Sep 17 00:00:00 2001 From: Darren Zhao Date: Mon, 27 Jun 2022 16:16:55 -0400 Subject: [PATCH 1/2] Fix bug with origOptions key iteration. --- src/nlp/totext.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nlp/totext.ts b/src/nlp/totext.ts index cbb614a1..7500595d 100644 --- a/src/nlp/totext.ts +++ b/src/nlp/totext.ts @@ -139,7 +139,7 @@ export default class ToText { if (rrule.origOptions.until && rrule.origOptions.count) return false for (const key in rrule.origOptions) { - if (contains(['dtstart', 'wkst', 'freq'], key)) return true + if (contains(['dtstart', 'wkst', 'freq'], key)) continue if (!contains(ToText.IMPLEMENTED[rrule.options.freq], key)) return false } From af3efec400e2bc0a2fc5a6017ca1257bf3c0abe8 Mon Sep 17 00:00:00 2001 From: Darren Zhao Date: Mon, 27 Jun 2022 16:47:53 -0400 Subject: [PATCH 2/2] Add test. --- test/nlp.test.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/nlp.test.ts b/test/nlp.test.ts index c64e7b44..1b78740b 100644 --- a/test/nlp.test.ts +++ b/test/nlp.test.ts @@ -1,5 +1,5 @@ import { expect } from 'chai' -import { RRule } from '../src' +import { Frequency, Options, RRule } from '../src' import { optionsToString } from '../src/optionstostring' import { DateFormatter } from '../src/nlp/totext' import { datetime } from './lib/utils' @@ -29,6 +29,11 @@ const texts = [ ['Every week for 20 times', 'RRULE:FREQ=WEEKLY;COUNT=20'], ] +const textsByOptions: [string, Partial][] = [ + // The option "byhour" is not fully convertible for monthly. + ['Every month on tuesday (~ approximate)', { dtstart: datetime(2022, 6, 1), freq: Frequency.MONTHLY, interval: 1, byweekday: 1, byhour: 1 }] +] + describe('NLP', () => { it('fromText()', function () { texts.forEach(function (item) { @@ -47,6 +52,13 @@ describe('NLP', () => { str + ' => ' + text ) }) + textsByOptions.forEach(function (item) { + const text = item[0] + const options = item[1] + expect(new RRule(options).toText().toLowerCase()).equals( + text.toLowerCase() + ) + }) }) it('parseText()', function () {