Skip to content

Commit

Permalink
Additional fixes for bySetPos and updated tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Pal authored and Steven Pal committed Oct 9, 2022
1 parent f888871 commit cc221aa
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions src/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ interface ICalEventInternalRepeatingData {
byDay?: ICalWeekday[];
byMonth?: number[];
byMonthDay?: number[];
bySetPos?: number;
bySetPos?: number[];
exclude?: ICalDateTimeValue[];
startOfWeek?: ICalWeekday;
}
Expand Down Expand Up @@ -669,11 +669,11 @@ export default class ICalEvent {
}
const bySetPosArray = Array.isArray(repeating.bySetPos) ? repeating.bySetPos : [repeating.bySetPos];
this.data.repeating.bySetPos = bySetPosArray.map(bySetPos => {
if (typeof bySetPos !== 'number' || bySetPos < -366 || bySetPos > 366 || bySetPos === 0) {
throw '`repeating.bySetPos` contains invalid value `' + bySetPos + '`!';
}
return bySetPos;
})
if (typeof bySetPos !== 'number' || bySetPos < -366 || bySetPos > 366 || bySetPos === 0) {
throw '`repeating.bySetPos` contains invalid value `' + bySetPos + '`!';
}
return bySetPos;
});
}

if (repeating.exclude) {
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface ICalRepeatingOptions {
byDay?: ICalWeekday[] | ICalWeekday;
byMonth?: number[] | number;
byMonthDay?: number[] | number;
bySetPos?: number;
bySetPos?: number[] | number;
exclude?: ICalDateTimeValue[] | ICalDateTimeValue;
startOfWeek?: ICalWeekday;
}
Expand Down
12 changes: 6 additions & 6 deletions test/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ describe('ical-generator Event', function () {
freq: ICalEventRepeatingFreq.MONTHLY,
interval: 2,
byDay: [ICalWeekday.SU],
bySetPos: 367
bySetPos: [367]
}
}, new ICalCalendar());
}, /`repeating\.bySetPos` contains invalid value `367`/);
Expand All @@ -901,7 +901,7 @@ describe('ical-generator Event', function () {
freq: ICalEventRepeatingFreq.MONTHLY,
interval: 2,
byDay: [ICalWeekday.SU],
bySetPos: -367
bySetPos: [-367]
}
}, new ICalCalendar());
}, /`repeating\.bySetPos` contains invalid value `-367`/);
Expand All @@ -915,7 +915,7 @@ describe('ical-generator Event', function () {
freq: ICalEventRepeatingFreq.MONTHLY,
interval: 2,
byDay: [ICalWeekday.SU],
bySetPos: 0
bySetPos: [0]
}
}, new ICalCalendar());
}, /`repeating\.bySetPos` contains invalid value `0`/);
Expand All @@ -930,7 +930,7 @@ describe('ical-generator Event', function () {
interval: 2,
byDay: [ICalWeekday.SU],
// @ts-ignore
bySetPos: 'FOO'
bySetPos: ['FOO']
}
}, new ICalCalendar());
}, /`repeating\.bySetPos` contains invalid value `FOO`/);
Expand All @@ -957,13 +957,13 @@ describe('ical-generator Event', function () {
e.repeating({
freq: ICalEventRepeatingFreq.MONTHLY,
byDay: [ICalWeekday.SU],
bySetPos: 2
bySetPos: [2]
});

const result = e.repeating();
assert.ok(result && !isRRule(result) && typeof result !== 'string');
assert.strictEqual(result.byDay?.length, 1);
assert.strictEqual(result.bySetPos, [2]);
assert.strictEqual(result.bySetPos?.length, 1);
});

it('should throw error when repeating.exclude is not valid', function () {
Expand Down
4 changes: 2 additions & 2 deletions test/issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('Issues', function () {
assert.ok(str.indexOf('RRULE:FREQ=MONTHLY;COUNT=3;INTERVAL=1;BYDAY=SU;BYSETPOS=3') > -1);
});

it('should work with repeating bySetPos by taking the first elemnt of the byDay array', function () {
it('should work with repeating bySetPos by taking all elements of the byDay array', function () {
const calendar = ical({
prodId: '//superman-industries.com//ical-generator//EN',
events: [{
Expand All @@ -79,7 +79,7 @@ describe('Issues', function () {
});

const str = calendar.toString();
assert.ok(str.indexOf('RRULE:FREQ=MONTHLY;COUNT=3;INTERVAL=1;BYDAY=MO;BYSETPOS=3') > -1);
assert.ok(str.indexOf('RRULE:FREQ=MONTHLY;COUNT=3;INTERVAL=1;BYDAY=MO,FR;BYSETPOS=3') > -1);
});
});

Expand Down

0 comments on commit cc221aa

Please sign in to comment.