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

Bugfix - Apply dtstart option when forceset: true #431

Open
wants to merge 1 commit 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
8 changes: 4 additions & 4 deletions src/rrulestr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ function buildRule (s: string, options: Partial<RRuleStrOptions>) {
) {
const rset = new RRuleSet(noCache)

rset.dtstart(dtstart)
rset.dtstart(options.dtstart || dtstart)
rset.tzid(tzid || undefined)

rrulevals.forEach(val => {
rset.rrule(
new RRule(
groomRruleOptions(val, dtstart, tzid),
groomRruleOptions(val, options.dtstart || dtstart, tzid),
noCache
)
)
Expand All @@ -133,7 +133,7 @@ function buildRule (s: string, options: Partial<RRuleStrOptions>) {
exrulevals.forEach(val => {
rset.exrule(
new RRule(
groomRruleOptions(val, dtstart, tzid),
groomRruleOptions(val, options.dtstart || dtstart, tzid),
noCache
)
)
Expand All @@ -143,7 +143,7 @@ function buildRule (s: string, options: Partial<RRuleStrOptions>) {
rset.exdate(date)
})

if (options.compatible && options.dtstart) rset.rdate(dtstart!)
if (options.compatible && options.dtstart) rset.rdate((options.dtstart || dtstart))
return rset
}

Expand Down
34 changes: 32 additions & 2 deletions test/rrulestr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,36 @@ describe('rrulestr', function () {
})
})

it('adds dtstart when forceset is applied', () => {
const rruleset = rrulestr(
'RRULE:FREQ=WEEKLY',
{
forceset: true,
dtstart: new Date(Date.UTC(1997, 8, 2, 9, 0, 0))
}
)

expect(rruleset.valueOf()).to.deep.equal([
"DTSTART:19970902T090000Z",
"RRULE:FREQ=WEEKLY"
])
})

it('adds dtstart from options overriding rule\'s dtstart', () => {
const rruleset = rrulestr(
'RRULE:DTSTART=19990104T110000Z;FREQ=WEEKLY;BYDAY=TU,WE',
{
forceset: true,
dtstart: new Date(Date.UTC(1997, 8, 2, 9, 0, 0))
}
)

expect(rruleset.valueOf()).to.deep.equal([
"DTSTART:19970902T090000Z",
"RRULE:FREQ=WEEKLY;BYDAY=TU,WE"
])
})

it('parses TZID', () => {
const rrule = rrulestr(
'DTSTART;TZID=America/New_York:19970902T090000\n' +
Expand Down Expand Up @@ -355,7 +385,7 @@ describe('rrulestr', function () {
"RRULE:FREQ=DAILY;INTERVAL=1",
"RDATE:20180720T111500Z",
"EXDATE:20180721T111500Z"
])
])
})

it('parses an RDATE with a TZID param', () => {
Expand All @@ -371,7 +401,7 @@ describe('rrulestr', function () {
"RRULE:FREQ=DAILY;INTERVAL=1",
"RDATE;TZID=America/Los_Angeles:20180720T111500",
"EXDATE;TZID=America/Los_Angeles:20180721T111500"
])
])
})
})

Expand Down