Skip to content

Commit

Permalink
Merge pull request #347 from epicfaace/getters
Browse files Browse the repository at this point in the history
Add getters for rrules, exrules, rdates, exdates
  • Loading branch information
davidgoli authored Jun 7, 2019
2 parents d2442c1 + 00df226 commit 7fd5993
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 1 deletion.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,22 @@ Same as `RRule.prototype.before`.

Same as `RRule.prototype.after`.

##### `RRuleSet.prototype.rrules()`

Get list of included rrules in this recurrence set.

##### `RRuleSet.prototype.exrules()`

Get list of excluded rrules in this recurrence set.

##### `RRuleSet.prototype.rdates()`

Get list of included datetimes in this recurrence set.

##### `RRuleSet.prototype.exdates()`

Get list of excluded datetimes in this recurrence set.

* * * * *

#### `rrulestr` Function
Expand Down
37 changes: 37 additions & 0 deletions src/rruleset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { includes } from './helpers'
import IterResult from './iterresult'
import { iterSet } from './iterset'
import { QueryMethodTypes, IterResultType } from './types'
import { rrulestr } from './rrulestr'
import { optionsToString } from './optionstostring'

function createGetterSetter <T> (fieldName: string) {
Expand Down Expand Up @@ -99,6 +100,42 @@ export default class RRuleSet extends RRule {
_addDate(date, this._exdate)
}

/**
* Get list of included rrules in this recurrence set.
*
* @return List of rrules
*/
rrules () {
return this._rrule.map(e => rrulestr(e.toString()))
}

/**
* Get list of excluded rrules in this recurrence set.
*
* @return List of exrules
*/
exrules () {
return this._exrule.map(e => rrulestr(e.toString()))
}

/**
* Get list of included datetimes in this recurrence set.
*
* @return List of rdates
*/
rdates () {
return this._rdate.map(e => new Date(e.getTime()))
}

/**
* Get list of included datetimes in this recurrence set.
*
* @return List of exdates
*/
exdates () {
return this._exdate.map(e => new Date(e.getTime()))
}

valueOf () {
let result: string[] = []

Expand Down
46 changes: 45 additions & 1 deletion test/rruleset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -727,4 +727,48 @@ describe('RRuleSet', function () {
expect(() => set.rdate('foo' as any)).to.throw()
expect(() => set.exdate('foo' as any)).to.throw()
})
})

describe('getters', () => {
it('rrules()', () => {
let set = new RRuleSet();
let rrule = new RRule({
freq: RRule.YEARLY,
count: 2,
dtstart: parse('19600101T090000'),
tzid: 'America/New_York'
});
set.rrule(rrule);

expect(set.rrules().map(e => e.toString())).eql([rrule.toString()]);
});

it('exrules()', () => {
let set = new RRuleSet();
let rrule = new RRule({
freq: RRule.YEARLY,
count: 2,
dtstart: parse('19600101T090000'),
tzid: 'America/New_York'
});
set.exrule(rrule);

expect(set.exrules().map(e => e.toString())).eql([rrule.toString()]);
});

it('rdates()', () => {
let set = new RRuleSet();
let dt = parse('19610201T090000');
set.rdate(dt);

expect(set.rdates()).eql([dt]);
});

it('exdates()', () => {
let set = new RRuleSet();
let dt = parse('19610201T090000');
set.exdate(dt);

expect(set.exdates()).eql([dt]);
});
});
});

0 comments on commit 7fd5993

Please sign in to comment.