diff --git a/src/nlp/totext.ts b/src/nlp/totext.ts index e77fd123..029f2c06 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', 'tzid', 'wkst', 'freq'], key)) return true + if (contains(['dtstart', 'tzid', 'wkst', 'freq'], key)) continue if (!contains(ToText.IMPLEMENTED[rrule.options.freq], key)) return false } diff --git a/test/nlp.test.ts b/test/nlp.test.ts index 8948616c..7eeab441 100644 --- a/test/nlp.test.ts +++ b/test/nlp.test.ts @@ -1,4 +1,4 @@ -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' @@ -6,10 +6,6 @@ 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'], @@ -32,6 +28,29 @@ 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, + }, + ], + // The option "byhour" is not fully convertible for weekly. + [ + 'Every week on Sunday at 10, 12 and 17 (~ approximate)', + { + freq: Frequency.WEEKLY, + byweekday: 6, + byhour: [10, 12, 17], + }, + ], +] + const toTexts = [ ...texts, [ @@ -57,6 +76,13 @@ describe('NLP', () => { text.toLowerCase() ) }) + textsByOptions.forEach(function (item) { + const text = item[0] + const options = item[1] + expect(new RRule(options).toText().toLowerCase()).toEqual( + text.toLowerCase() + ) + }) }) it('parseText()', function () {