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

Fix bug with option key ordering. #527

Open
wants to merge 3 commits 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
2 changes: 1 addition & 1 deletion src/nlp/totext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
36 changes: 31 additions & 5 deletions test/nlp.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
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'

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',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed this and moved it down in with "~ approximate" because it is technically not fully supported; byhour is not fully convertible for weekly.

],
['Every week', 'RRULE:FREQ=WEEKLY'],
['Every hour', 'RRULE:FREQ=HOURLY'],
['Every 4 hours', 'RRULE:INTERVAL=4;FREQ=HOURLY'],
Expand All @@ -32,6 +28,29 @@ const texts = [
['Every week for 20 times', 'RRULE:FREQ=WEEKLY;COUNT=20'],
]

const textsByOptions: [string, Partial<Options>][] = [
// 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,
[
Expand All @@ -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 () {
Expand Down
Loading