rrule-rust 3.0.0-alpha.4 → 3.0.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -25,15 +25,14 @@ If you need a browser-compatible version with WASM support:
25
25
  For more usage examples and advanced scenarios, see the [tests directory](https://github.com/lsndr/rrule-rust/tree/master/tests) in the repository.
26
26
 
27
27
  ```typescript
28
- import { RRule, RRuleSet, Frequency, DateTime } from 'rrule-rust';
28
+ import { RRule, RRuleSet, Frequency, DateTime, DtStart } from 'rrule-rust';
29
29
 
30
30
  const rrule = new RRule({
31
31
  frequency: Frequency.Daily,
32
32
  count: 5,
33
33
  });
34
34
  const set = new RRuleSet({
35
- dtstart: DateTime.create(1997, 9, 2, 9, 0, 0, false),
36
- tzid: 'US/Eastern',
35
+ dtstart: new DtStart(DateTime.local(1997, 9, 2, 9, 0, 0), 'US/Eastern'),
37
36
  rrules: [rrule],
38
37
  });
39
38
 
@@ -86,10 +86,6 @@ export class DateTime {
86
86
  static fromNumeric(numeric) {
87
87
  return new DateTime(numeric);
88
88
  }
89
- /** @internal */
90
- static fromPlainOrInstance(datetime) {
91
- return datetime instanceof DateTime ? datetime : this.fromPlain(datetime);
92
- }
93
89
  toPlain(options) {
94
90
  return {
95
91
  year: this.year,
@@ -0,0 +1,19 @@
1
+ import { DateTime, type DateTimeLike } from './datetime';
2
+ export interface DtStartOptions {
3
+ datetime: DateTime;
4
+ tzid?: string;
5
+ }
6
+ export interface DtStartLike {
7
+ datetime: DateTimeLike;
8
+ tzid?: string;
9
+ }
10
+ export declare class DtStart {
11
+ readonly datetime: DateTime;
12
+ readonly tzid?: string;
13
+ constructor(datetime: DateTime, tzid?: string);
14
+ constructor(options: DtStartOptions);
15
+ static fromPlain(plain: DtStartLike): DtStart;
16
+ setTzid(tzid: string): DtStart;
17
+ setDatetime(datetime: DateTime): DtStart;
18
+ toPlain(): DtStartLike;
19
+ }
@@ -0,0 +1,37 @@
1
+ import { DateTime } from './datetime';
2
+ export class DtStart {
3
+ constructor(datetimeOrOptions, tzid) {
4
+ if ('datetime' in datetimeOrOptions) {
5
+ this.datetime = datetimeOrOptions.datetime;
6
+ this.tzid = datetimeOrOptions.tzid;
7
+ }
8
+ else {
9
+ this.datetime = datetimeOrOptions;
10
+ this.tzid = tzid;
11
+ }
12
+ }
13
+ static fromPlain(plain) {
14
+ return new this({
15
+ datetime: DateTime.fromPlain(plain.datetime),
16
+ tzid: plain.tzid,
17
+ });
18
+ }
19
+ setTzid(tzid) {
20
+ return new DtStart({
21
+ datetime: this.datetime,
22
+ tzid,
23
+ });
24
+ }
25
+ setDatetime(datetime) {
26
+ return new DtStart({
27
+ datetime: datetime,
28
+ tzid: this.tzid,
29
+ });
30
+ }
31
+ toPlain() {
32
+ return {
33
+ datetime: this.datetime.toPlain(),
34
+ tzid: this.tzid,
35
+ };
36
+ }
37
+ }
@@ -1,3 +1,4 @@
1
1
  export * from './rrule-set';
2
2
  export * from './rrule';
3
3
  export * from './datetime';
4
+ export * from './dtstart';
@@ -1,3 +1,4 @@
1
1
  export * from './rrule-set';
2
2
  export * from './rrule';
3
3
  export * from './datetime';
4
+ export * from './dtstart';
@@ -1,45 +1,42 @@
1
1
  import { RRule, type RRuleLike } from './rrule';
2
2
  import { DateTime, type DateTimeLike } from './datetime';
3
+ import { DtStart, type DtStartLike } from './dtstart';
3
4
  export interface RRuleSetOptions {
4
- readonly dtstart: DateTime | DateTimeLike;
5
- readonly tzid?: string;
6
- readonly rrules?: readonly (RRule | RRuleLike)[];
7
- readonly exrules?: readonly (RRule | RRuleLike)[];
8
- readonly exdates?: readonly (DateTime | DateTimeLike)[];
9
- readonly rdates?: readonly (DateTime | DateTimeLike)[];
5
+ readonly dtstart: DtStart;
6
+ readonly rrules?: readonly RRule[];
7
+ readonly exrules?: readonly RRule[];
8
+ readonly exdates?: readonly DateTime[];
9
+ readonly rdates?: readonly DateTime[];
10
10
  }
11
11
  export interface RRuleSetLike {
12
- readonly dtstart: DateTimeLike;
13
- readonly tzid?: string;
12
+ readonly dtstart: DtStartLike;
14
13
  readonly rrules: readonly RRuleLike[];
15
14
  readonly exrules: readonly RRuleLike[];
16
15
  readonly exdates: readonly DateTimeLike[];
17
16
  readonly rdates: readonly DateTimeLike[];
18
17
  }
19
18
  export declare class RRuleSet implements Iterable<DateTime> {
20
- readonly dtstart: DateTime;
21
- readonly tzid: string;
19
+ readonly dtstart: DtStart;
22
20
  readonly rrules: readonly RRule[];
23
21
  readonly exrules: readonly RRule[];
24
22
  readonly exdates: readonly DateTime[];
25
23
  readonly rdates: readonly DateTime[];
26
- constructor(dtstart: DateTime | DateTimeLike, tzid?: string);
24
+ constructor(dtstart: DtStart);
27
25
  constructor(options: RRuleSetOptions);
28
26
  /**
29
27
  * Parses a string into an RRuleSet.
30
28
  */
31
29
  static parse(str: string): RRuleSet;
32
30
  static fromPlain(plain: RRuleSetLike): RRuleSet;
33
- setDtstart(dtstart: DateTime | DateTimeLike): RRuleSet;
34
- setTzid(tzid: string): RRuleSet;
35
- addRrule(rrule: RRule | RRuleLike): RRuleSet;
36
- setRrules(rrules: readonly (RRule | RRuleLike)[]): RRuleSet;
37
- addExrule(rrule: RRule | RRuleLike): RRuleSet;
38
- setExrules(rrules: readonly (RRule | RRuleLike)[]): RRuleSet;
39
- addExdate(datetime: DateTime | DateTimeLike): RRuleSet;
40
- setExdates(datetimes: readonly (DateTime | DateTimeLike)[]): RRuleSet;
41
- addRdate(datetime: DateTime | DateTimeLike): RRuleSet;
42
- setRdates(datetimes: readonly (DateTime | DateTimeLike)[]): RRuleSet;
31
+ setDtstart(dtstart: DtStart): RRuleSet;
32
+ addRrule(rrule: RRule): RRuleSet;
33
+ setRrules(rrules: readonly RRule[]): RRuleSet;
34
+ addExrule(rrule: RRule): RRuleSet;
35
+ setExrules(rrules: readonly RRule[]): RRuleSet;
36
+ addExdate(datetime: DateTime): RRuleSet;
37
+ setExdates(datetimes: readonly DateTime[]): RRuleSet;
38
+ addRdate(datetime: DateTime): RRuleSet;
39
+ setRdates(datetimes: readonly DateTime[]): RRuleSet;
43
40
  /**
44
41
  * Returns all the occurrences of the rrule.
45
42
  *
@@ -66,4 +63,5 @@ export declare class RRuleSet implements Iterable<DateTime> {
66
63
  */
67
64
  toPlain(): RRuleSetLike;
68
65
  [Symbol.iterator](): Iterator<DateTime, any, any>;
66
+ private toOptions;
69
67
  }
@@ -1,29 +1,23 @@
1
1
  import { RRule } from './rrule';
2
2
  import { RRuleSet as Rust } from './lib';
3
3
  import { DateTime } from './datetime';
4
+ import { DtStart } from './dtstart';
4
5
  export class RRuleSet {
5
- constructor(optionsOrDtstart, tzid) {
6
- if (optionsOrDtstart !== undefined &&
7
- !(optionsOrDtstart instanceof DateTime) &&
8
- 'dtstart' in optionsOrDtstart) {
9
- this.dtstart = DateTime.fromPlainOrInstance(optionsOrDtstart.dtstart);
10
- this.tzid = optionsOrDtstart.tzid ?? 'UTC';
11
- this.rrules = (optionsOrDtstart?.rrules ?? []).map(RRule.fromPlainOrInstance.bind(RRule));
12
- this.exrules = (optionsOrDtstart?.exrules ?? []).map(RRule.fromPlainOrInstance.bind(RRule));
13
- this.exdates = (optionsOrDtstart?.exdates ?? []).map(DateTime.fromPlainOrInstance.bind(DateTime));
14
- this.rdates = (optionsOrDtstart?.rdates ?? []).map(DateTime.fromPlainOrInstance.bind(DateTime));
6
+ constructor(optionsOrDtstart) {
7
+ if ('dtstart' in optionsOrDtstart) {
8
+ this.dtstart = optionsOrDtstart.dtstart;
9
+ this.rrules = optionsOrDtstart?.rrules ?? [];
10
+ this.exrules = optionsOrDtstart?.exrules ?? [];
11
+ this.exdates = optionsOrDtstart?.exdates ?? [];
12
+ this.rdates = optionsOrDtstart?.rdates ?? [];
15
13
  }
16
- else if (optionsOrDtstart instanceof DateTime) {
14
+ else {
17
15
  this.dtstart = optionsOrDtstart;
18
- this.tzid = tzid ?? 'UTC';
19
16
  this.rrules = [];
20
17
  this.exrules = [];
21
18
  this.exdates = [];
22
19
  this.rdates = [];
23
20
  }
24
- else {
25
- throw new TypeError('Invalid arguments');
26
- }
27
21
  }
28
22
  /**
29
23
  * Parses a string into an RRuleSet.
@@ -33,15 +27,23 @@ export class RRuleSet {
33
27
  return this.fromRust(rust);
34
28
  }
35
29
  static fromPlain(plain) {
36
- return new RRuleSet(plain);
30
+ return new RRuleSet({
31
+ dtstart: DtStart.fromPlain(plain.dtstart),
32
+ rrules: plain.rrules.map((rrule) => RRule.fromPlain(rrule)),
33
+ exrules: plain.exrules.map((rrule) => RRule.fromPlain(rrule)),
34
+ exdates: plain.exdates.map((datetime) => DateTime.fromPlain(datetime)),
35
+ rdates: plain.rdates.map((datetime) => DateTime.fromPlain(datetime)),
36
+ });
37
37
  }
38
38
  /**
39
39
  * @internal
40
40
  */
41
41
  static fromRust(rust) {
42
42
  const set = new RRuleSet({
43
- dtstart: DateTime.fromNumeric(rust.dtstart),
44
- tzid: rust.tzid ?? undefined,
43
+ dtstart: new DtStart({
44
+ datetime: DateTime.fromNumeric(rust.dtstart),
45
+ tzid: rust.tzid ?? undefined,
46
+ }),
45
47
  rrules: rust.rrules.map((rrule) => RRule.fromRust(rrule)),
46
48
  exrules: rust.exrules.map((rrule) => RRule.fromRust(rrule)),
47
49
  exdates: rust.exdates.map((datetime) => DateTime.fromNumeric(datetime)),
@@ -52,61 +54,55 @@ export class RRuleSet {
52
54
  }
53
55
  setDtstart(dtstart) {
54
56
  return new RRuleSet({
55
- ...this.toPlain(),
57
+ ...this.toOptions(),
56
58
  dtstart: dtstart,
57
59
  });
58
60
  }
59
- setTzid(tzid) {
60
- return new RRuleSet({
61
- ...this.toPlain(),
62
- tzid: tzid,
63
- });
64
- }
65
61
  addRrule(rrule) {
66
62
  return new RRuleSet({
67
- ...this.toPlain(),
63
+ ...this.toOptions(),
68
64
  rrules: [...this.rrules, rrule],
69
65
  });
70
66
  }
71
67
  setRrules(rrules) {
72
68
  return new RRuleSet({
73
- ...this.toPlain(),
69
+ ...this.toOptions(),
74
70
  rrules: rrules,
75
71
  });
76
72
  }
77
73
  addExrule(rrule) {
78
74
  return new RRuleSet({
79
- ...this.toPlain(),
75
+ ...this.toOptions(),
80
76
  exrules: [...this.exrules, rrule],
81
77
  });
82
78
  }
83
79
  setExrules(rrules) {
84
80
  return new RRuleSet({
85
- ...this.toPlain(),
81
+ ...this.toOptions(),
86
82
  exrules: rrules,
87
83
  });
88
84
  }
89
85
  addExdate(datetime) {
90
86
  return new RRuleSet({
91
- ...this.toPlain(),
87
+ ...this.toOptions(),
92
88
  exdates: [...this.exdates, datetime],
93
89
  });
94
90
  }
95
91
  setExdates(datetimes) {
96
92
  return new RRuleSet({
97
- ...this.toPlain(),
93
+ ...this.toOptions(),
98
94
  exdates: datetimes,
99
95
  });
100
96
  }
101
97
  addRdate(datetime) {
102
98
  return new RRuleSet({
103
- ...this.toPlain(),
99
+ ...this.toOptions(),
104
100
  rdates: [...this.rdates, datetime],
105
101
  });
106
102
  }
107
103
  setRdates(datetimes) {
108
104
  return new RRuleSet({
109
- ...this.toPlain(),
105
+ ...this.toOptions(),
110
106
  rdates: datetimes,
111
107
  });
112
108
  }
@@ -144,7 +140,7 @@ export class RRuleSet {
144
140
  * @internal
145
141
  */
146
142
  toRust() {
147
- this.rust ??= new Rust(this.dtstart.toNumeric(), this.tzid, this.rrules.map((rrule) => rrule.toRust()), this.exrules.map((rrule) => rrule.toRust()), this.exdates.map((datetime) => datetime.toNumeric()), this.rdates.map((datetime) => datetime.toNumeric()));
143
+ this.rust ??= new Rust(this.dtstart.datetime.toNumeric(), this.dtstart.tzid, this.rrules.map((rrule) => rrule.toRust()), this.exrules.map((rrule) => rrule.toRust()), this.exdates.map((datetime) => datetime.toNumeric()), this.rdates.map((datetime) => datetime.toNumeric()));
148
144
  return this.rust;
149
145
  }
150
146
  toString() {
@@ -156,7 +152,6 @@ export class RRuleSet {
156
152
  toPlain() {
157
153
  return {
158
154
  dtstart: this.dtstart.toPlain(),
159
- tzid: this.tzid,
160
155
  rrules: this.rrules.map((rrule) => rrule.toPlain()),
161
156
  exrules: this.exrules.map((rrule) => rrule.toPlain()),
162
157
  exdates: this.exdates.map((rrule) => rrule.toPlain()),
@@ -181,4 +176,13 @@ export class RRuleSet {
181
176
  },
182
177
  };
183
178
  }
179
+ toOptions() {
180
+ return {
181
+ dtstart: this.dtstart,
182
+ rrules: this.rrules,
183
+ exrules: this.exrules,
184
+ exdates: this.exdates,
185
+ rdates: this.rdates,
186
+ };
187
+ }
184
188
  }
@@ -45,7 +45,7 @@ export interface RRuleOptions {
45
45
  readonly frequency: Frequency;
46
46
  readonly interval?: number;
47
47
  readonly count?: number;
48
- readonly until?: DateTime | DateTimeLike;
48
+ readonly until?: DateTime;
49
49
  readonly byWeekday?: readonly (NWeekday | Weekday)[];
50
50
  readonly byHour?: readonly number[];
51
51
  readonly byMinute?: readonly number[];
@@ -108,7 +108,8 @@ export declare class RRule {
108
108
  setByWeekno(weekNumbers: readonly number[]): RRule;
109
109
  setByYearday(days: readonly number[]): RRule;
110
110
  setWeekstart(day: Weekday): RRule;
111
- setUntil(datetime: DateTime | DateTimeLike): RRule;
111
+ setUntil(datetime: DateTime): RRule;
112
112
  toString(): string;
113
113
  toPlain(): RRuleLike;
114
+ private toOptions;
114
115
  }
@@ -79,7 +79,7 @@ export class RRule {
79
79
  return new this({
80
80
  frequency: rrule.frequency,
81
81
  interval: rrule.interval,
82
- until: rrule.until,
82
+ until: rrule.until && DateTime.fromPlain(rrule.until),
83
83
  count: rrule.count,
84
84
  byWeekday: rrule.byWeekday,
85
85
  byHour: rrule.byHour,
@@ -116,53 +116,47 @@ export class RRule {
116
116
  rrule.rust = rust;
117
117
  return rrule;
118
118
  }
119
- /**
120
- * @internal
121
- */
122
- static fromPlainOrInstance(rrule) {
123
- return rrule instanceof RRule ? rrule : this.fromPlain(rrule);
124
- }
125
119
  setFrequency(frequency) {
126
- return new RRule({ ...this.toPlain(), frequency });
120
+ return new RRule({ ...this.toOptions(), frequency });
127
121
  }
128
122
  setInterval(interval) {
129
- return new RRule({ ...this.toPlain(), interval });
123
+ return new RRule({ ...this.toOptions(), interval });
130
124
  }
131
125
  setCount(count) {
132
- return new RRule({ ...this.toPlain(), count });
126
+ return new RRule({ ...this.toOptions(), count });
133
127
  }
134
128
  setByWeekday(weekdays) {
135
- return new RRule({ ...this.toPlain(), byWeekday: weekdays });
129
+ return new RRule({ ...this.toOptions(), byWeekday: weekdays });
136
130
  }
137
131
  setByHour(hours) {
138
- return new RRule({ ...this.toPlain(), byHour: hours });
132
+ return new RRule({ ...this.toOptions(), byHour: hours });
139
133
  }
140
134
  setByMinute(minutes) {
141
- return new RRule({ ...this.toPlain(), byMinute: minutes });
135
+ return new RRule({ ...this.toOptions(), byMinute: minutes });
142
136
  }
143
137
  setBySecond(seconds) {
144
- return new RRule({ ...this.toPlain(), bySecond: seconds });
138
+ return new RRule({ ...this.toOptions(), bySecond: seconds });
145
139
  }
146
140
  setByMonthday(days) {
147
- return new RRule({ ...this.toPlain(), byMonthday: days });
141
+ return new RRule({ ...this.toOptions(), byMonthday: days });
148
142
  }
149
143
  setBySetpos(poses) {
150
- return new RRule({ ...this.toPlain(), bySetpos: poses });
144
+ return new RRule({ ...this.toOptions(), bySetpos: poses });
151
145
  }
152
146
  setByMonth(months) {
153
- return new RRule({ ...this.toPlain(), byMonth: months });
147
+ return new RRule({ ...this.toOptions(), byMonth: months });
154
148
  }
155
149
  setByWeekno(weekNumbers) {
156
- return new RRule({ ...this.toPlain(), byWeekno: weekNumbers });
150
+ return new RRule({ ...this.toOptions(), byWeekno: weekNumbers });
157
151
  }
158
152
  setByYearday(days) {
159
- return new RRule({ ...this.toPlain(), byYearday: days });
153
+ return new RRule({ ...this.toOptions(), byYearday: days });
160
154
  }
161
155
  setWeekstart(day) {
162
- return new RRule({ ...this.toPlain(), weekstart: day });
156
+ return new RRule({ ...this.toOptions(), weekstart: day });
163
157
  }
164
158
  setUntil(datetime) {
165
- return new RRule({ ...this.toPlain(), until: datetime });
159
+ return new RRule({ ...this.toOptions(), until: datetime });
166
160
  }
167
161
  toString() {
168
162
  return this.toRust().toString();
@@ -192,4 +186,22 @@ export class RRule {
192
186
  until: this.until?.toPlain(),
193
187
  };
194
188
  }
189
+ toOptions() {
190
+ return {
191
+ frequency: this.frequency,
192
+ interval: this.interval,
193
+ count: this.count,
194
+ byWeekday: this.byWeekday,
195
+ byHour: this.byHour,
196
+ byMinute: this.byMinute,
197
+ bySecond: this.bySecond,
198
+ byMonthday: this.byMonthday,
199
+ bySetpos: this.bySetpos,
200
+ byMonth: this.byMonth,
201
+ byWeekno: this.byWeekno,
202
+ byYearday: this.byYearday,
203
+ weekstart: this.weekstart,
204
+ until: this.until,
205
+ };
206
+ }
195
207
  }
@@ -89,10 +89,6 @@ class DateTime {
89
89
  static fromNumeric(numeric) {
90
90
  return new DateTime(numeric);
91
91
  }
92
- /** @internal */
93
- static fromPlainOrInstance(datetime) {
94
- return datetime instanceof DateTime ? datetime : this.fromPlain(datetime);
95
- }
96
92
  toPlain(options) {
97
93
  return {
98
94
  year: this.year,
@@ -0,0 +1,19 @@
1
+ import { DateTime, type DateTimeLike } from './datetime';
2
+ export interface DtStartOptions {
3
+ datetime: DateTime;
4
+ tzid?: string;
5
+ }
6
+ export interface DtStartLike {
7
+ datetime: DateTimeLike;
8
+ tzid?: string;
9
+ }
10
+ export declare class DtStart {
11
+ readonly datetime: DateTime;
12
+ readonly tzid?: string;
13
+ constructor(datetime: DateTime, tzid?: string);
14
+ constructor(options: DtStartOptions);
15
+ static fromPlain(plain: DtStartLike): DtStart;
16
+ setTzid(tzid: string): DtStart;
17
+ setDatetime(datetime: DateTime): DtStart;
18
+ toPlain(): DtStartLike;
19
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DtStart = void 0;
4
+ const datetime_1 = require("./datetime");
5
+ class DtStart {
6
+ constructor(datetimeOrOptions, tzid) {
7
+ if ('datetime' in datetimeOrOptions) {
8
+ this.datetime = datetimeOrOptions.datetime;
9
+ this.tzid = datetimeOrOptions.tzid;
10
+ }
11
+ else {
12
+ this.datetime = datetimeOrOptions;
13
+ this.tzid = tzid;
14
+ }
15
+ }
16
+ static fromPlain(plain) {
17
+ return new this({
18
+ datetime: datetime_1.DateTime.fromPlain(plain.datetime),
19
+ tzid: plain.tzid,
20
+ });
21
+ }
22
+ setTzid(tzid) {
23
+ return new DtStart({
24
+ datetime: this.datetime,
25
+ tzid,
26
+ });
27
+ }
28
+ setDatetime(datetime) {
29
+ return new DtStart({
30
+ datetime: datetime,
31
+ tzid: this.tzid,
32
+ });
33
+ }
34
+ toPlain() {
35
+ return {
36
+ datetime: this.datetime.toPlain(),
37
+ tzid: this.tzid,
38
+ };
39
+ }
40
+ }
41
+ exports.DtStart = DtStart;
@@ -1,3 +1,4 @@
1
1
  export * from './rrule-set';
2
2
  export * from './rrule';
3
3
  export * from './datetime';
4
+ export * from './dtstart';
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./rrule-set"), exports);
18
18
  __exportStar(require("./rrule"), exports);
19
19
  __exportStar(require("./datetime"), exports);
20
+ __exportStar(require("./dtstart"), exports);
@@ -1,45 +1,42 @@
1
1
  import { RRule, type RRuleLike } from './rrule';
2
2
  import { DateTime, type DateTimeLike } from './datetime';
3
+ import { DtStart, type DtStartLike } from './dtstart';
3
4
  export interface RRuleSetOptions {
4
- readonly dtstart: DateTime | DateTimeLike;
5
- readonly tzid?: string;
6
- readonly rrules?: readonly (RRule | RRuleLike)[];
7
- readonly exrules?: readonly (RRule | RRuleLike)[];
8
- readonly exdates?: readonly (DateTime | DateTimeLike)[];
9
- readonly rdates?: readonly (DateTime | DateTimeLike)[];
5
+ readonly dtstart: DtStart;
6
+ readonly rrules?: readonly RRule[];
7
+ readonly exrules?: readonly RRule[];
8
+ readonly exdates?: readonly DateTime[];
9
+ readonly rdates?: readonly DateTime[];
10
10
  }
11
11
  export interface RRuleSetLike {
12
- readonly dtstart: DateTimeLike;
13
- readonly tzid?: string;
12
+ readonly dtstart: DtStartLike;
14
13
  readonly rrules: readonly RRuleLike[];
15
14
  readonly exrules: readonly RRuleLike[];
16
15
  readonly exdates: readonly DateTimeLike[];
17
16
  readonly rdates: readonly DateTimeLike[];
18
17
  }
19
18
  export declare class RRuleSet implements Iterable<DateTime> {
20
- readonly dtstart: DateTime;
21
- readonly tzid: string;
19
+ readonly dtstart: DtStart;
22
20
  readonly rrules: readonly RRule[];
23
21
  readonly exrules: readonly RRule[];
24
22
  readonly exdates: readonly DateTime[];
25
23
  readonly rdates: readonly DateTime[];
26
- constructor(dtstart: DateTime | DateTimeLike, tzid?: string);
24
+ constructor(dtstart: DtStart);
27
25
  constructor(options: RRuleSetOptions);
28
26
  /**
29
27
  * Parses a string into an RRuleSet.
30
28
  */
31
29
  static parse(str: string): RRuleSet;
32
30
  static fromPlain(plain: RRuleSetLike): RRuleSet;
33
- setDtstart(dtstart: DateTime | DateTimeLike): RRuleSet;
34
- setTzid(tzid: string): RRuleSet;
35
- addRrule(rrule: RRule | RRuleLike): RRuleSet;
36
- setRrules(rrules: readonly (RRule | RRuleLike)[]): RRuleSet;
37
- addExrule(rrule: RRule | RRuleLike): RRuleSet;
38
- setExrules(rrules: readonly (RRule | RRuleLike)[]): RRuleSet;
39
- addExdate(datetime: DateTime | DateTimeLike): RRuleSet;
40
- setExdates(datetimes: readonly (DateTime | DateTimeLike)[]): RRuleSet;
41
- addRdate(datetime: DateTime | DateTimeLike): RRuleSet;
42
- setRdates(datetimes: readonly (DateTime | DateTimeLike)[]): RRuleSet;
31
+ setDtstart(dtstart: DtStart): RRuleSet;
32
+ addRrule(rrule: RRule): RRuleSet;
33
+ setRrules(rrules: readonly RRule[]): RRuleSet;
34
+ addExrule(rrule: RRule): RRuleSet;
35
+ setExrules(rrules: readonly RRule[]): RRuleSet;
36
+ addExdate(datetime: DateTime): RRuleSet;
37
+ setExdates(datetimes: readonly DateTime[]): RRuleSet;
38
+ addRdate(datetime: DateTime): RRuleSet;
39
+ setRdates(datetimes: readonly DateTime[]): RRuleSet;
43
40
  /**
44
41
  * Returns all the occurrences of the rrule.
45
42
  *
@@ -66,4 +63,5 @@ export declare class RRuleSet implements Iterable<DateTime> {
66
63
  */
67
64
  toPlain(): RRuleSetLike;
68
65
  [Symbol.iterator](): Iterator<DateTime, any, any>;
66
+ private toOptions;
69
67
  }
@@ -4,29 +4,23 @@ exports.RRuleSet = void 0;
4
4
  const rrule_1 = require("./rrule");
5
5
  const lib_1 = require("./lib");
6
6
  const datetime_1 = require("./datetime");
7
+ const dtstart_1 = require("./dtstart");
7
8
  class RRuleSet {
8
- constructor(optionsOrDtstart, tzid) {
9
- if (optionsOrDtstart !== undefined &&
10
- !(optionsOrDtstart instanceof datetime_1.DateTime) &&
11
- 'dtstart' in optionsOrDtstart) {
12
- this.dtstart = datetime_1.DateTime.fromPlainOrInstance(optionsOrDtstart.dtstart);
13
- this.tzid = optionsOrDtstart.tzid ?? 'UTC';
14
- this.rrules = (optionsOrDtstart?.rrules ?? []).map(rrule_1.RRule.fromPlainOrInstance.bind(rrule_1.RRule));
15
- this.exrules = (optionsOrDtstart?.exrules ?? []).map(rrule_1.RRule.fromPlainOrInstance.bind(rrule_1.RRule));
16
- this.exdates = (optionsOrDtstart?.exdates ?? []).map(datetime_1.DateTime.fromPlainOrInstance.bind(datetime_1.DateTime));
17
- this.rdates = (optionsOrDtstart?.rdates ?? []).map(datetime_1.DateTime.fromPlainOrInstance.bind(datetime_1.DateTime));
9
+ constructor(optionsOrDtstart) {
10
+ if ('dtstart' in optionsOrDtstart) {
11
+ this.dtstart = optionsOrDtstart.dtstart;
12
+ this.rrules = optionsOrDtstart?.rrules ?? [];
13
+ this.exrules = optionsOrDtstart?.exrules ?? [];
14
+ this.exdates = optionsOrDtstart?.exdates ?? [];
15
+ this.rdates = optionsOrDtstart?.rdates ?? [];
18
16
  }
19
- else if (optionsOrDtstart instanceof datetime_1.DateTime) {
17
+ else {
20
18
  this.dtstart = optionsOrDtstart;
21
- this.tzid = tzid ?? 'UTC';
22
19
  this.rrules = [];
23
20
  this.exrules = [];
24
21
  this.exdates = [];
25
22
  this.rdates = [];
26
23
  }
27
- else {
28
- throw new TypeError('Invalid arguments');
29
- }
30
24
  }
31
25
  /**
32
26
  * Parses a string into an RRuleSet.
@@ -36,15 +30,23 @@ class RRuleSet {
36
30
  return this.fromRust(rust);
37
31
  }
38
32
  static fromPlain(plain) {
39
- return new RRuleSet(plain);
33
+ return new RRuleSet({
34
+ dtstart: dtstart_1.DtStart.fromPlain(plain.dtstart),
35
+ rrules: plain.rrules.map((rrule) => rrule_1.RRule.fromPlain(rrule)),
36
+ exrules: plain.exrules.map((rrule) => rrule_1.RRule.fromPlain(rrule)),
37
+ exdates: plain.exdates.map((datetime) => datetime_1.DateTime.fromPlain(datetime)),
38
+ rdates: plain.rdates.map((datetime) => datetime_1.DateTime.fromPlain(datetime)),
39
+ });
40
40
  }
41
41
  /**
42
42
  * @internal
43
43
  */
44
44
  static fromRust(rust) {
45
45
  const set = new RRuleSet({
46
- dtstart: datetime_1.DateTime.fromNumeric(rust.dtstart),
47
- tzid: rust.tzid ?? undefined,
46
+ dtstart: new dtstart_1.DtStart({
47
+ datetime: datetime_1.DateTime.fromNumeric(rust.dtstart),
48
+ tzid: rust.tzid ?? undefined,
49
+ }),
48
50
  rrules: rust.rrules.map((rrule) => rrule_1.RRule.fromRust(rrule)),
49
51
  exrules: rust.exrules.map((rrule) => rrule_1.RRule.fromRust(rrule)),
50
52
  exdates: rust.exdates.map((datetime) => datetime_1.DateTime.fromNumeric(datetime)),
@@ -55,61 +57,55 @@ class RRuleSet {
55
57
  }
56
58
  setDtstart(dtstart) {
57
59
  return new RRuleSet({
58
- ...this.toPlain(),
60
+ ...this.toOptions(),
59
61
  dtstart: dtstart,
60
62
  });
61
63
  }
62
- setTzid(tzid) {
63
- return new RRuleSet({
64
- ...this.toPlain(),
65
- tzid: tzid,
66
- });
67
- }
68
64
  addRrule(rrule) {
69
65
  return new RRuleSet({
70
- ...this.toPlain(),
66
+ ...this.toOptions(),
71
67
  rrules: [...this.rrules, rrule],
72
68
  });
73
69
  }
74
70
  setRrules(rrules) {
75
71
  return new RRuleSet({
76
- ...this.toPlain(),
72
+ ...this.toOptions(),
77
73
  rrules: rrules,
78
74
  });
79
75
  }
80
76
  addExrule(rrule) {
81
77
  return new RRuleSet({
82
- ...this.toPlain(),
78
+ ...this.toOptions(),
83
79
  exrules: [...this.exrules, rrule],
84
80
  });
85
81
  }
86
82
  setExrules(rrules) {
87
83
  return new RRuleSet({
88
- ...this.toPlain(),
84
+ ...this.toOptions(),
89
85
  exrules: rrules,
90
86
  });
91
87
  }
92
88
  addExdate(datetime) {
93
89
  return new RRuleSet({
94
- ...this.toPlain(),
90
+ ...this.toOptions(),
95
91
  exdates: [...this.exdates, datetime],
96
92
  });
97
93
  }
98
94
  setExdates(datetimes) {
99
95
  return new RRuleSet({
100
- ...this.toPlain(),
96
+ ...this.toOptions(),
101
97
  exdates: datetimes,
102
98
  });
103
99
  }
104
100
  addRdate(datetime) {
105
101
  return new RRuleSet({
106
- ...this.toPlain(),
102
+ ...this.toOptions(),
107
103
  rdates: [...this.rdates, datetime],
108
104
  });
109
105
  }
110
106
  setRdates(datetimes) {
111
107
  return new RRuleSet({
112
- ...this.toPlain(),
108
+ ...this.toOptions(),
113
109
  rdates: datetimes,
114
110
  });
115
111
  }
@@ -147,7 +143,7 @@ class RRuleSet {
147
143
  * @internal
148
144
  */
149
145
  toRust() {
150
- this.rust ??= new lib_1.RRuleSet(this.dtstart.toNumeric(), this.tzid, this.rrules.map((rrule) => rrule.toRust()), this.exrules.map((rrule) => rrule.toRust()), this.exdates.map((datetime) => datetime.toNumeric()), this.rdates.map((datetime) => datetime.toNumeric()));
146
+ this.rust ??= new lib_1.RRuleSet(this.dtstart.datetime.toNumeric(), this.dtstart.tzid, this.rrules.map((rrule) => rrule.toRust()), this.exrules.map((rrule) => rrule.toRust()), this.exdates.map((datetime) => datetime.toNumeric()), this.rdates.map((datetime) => datetime.toNumeric()));
151
147
  return this.rust;
152
148
  }
153
149
  toString() {
@@ -159,7 +155,6 @@ class RRuleSet {
159
155
  toPlain() {
160
156
  return {
161
157
  dtstart: this.dtstart.toPlain(),
162
- tzid: this.tzid,
163
158
  rrules: this.rrules.map((rrule) => rrule.toPlain()),
164
159
  exrules: this.exrules.map((rrule) => rrule.toPlain()),
165
160
  exdates: this.exdates.map((rrule) => rrule.toPlain()),
@@ -184,5 +179,14 @@ class RRuleSet {
184
179
  },
185
180
  };
186
181
  }
182
+ toOptions() {
183
+ return {
184
+ dtstart: this.dtstart,
185
+ rrules: this.rrules,
186
+ exrules: this.exrules,
187
+ exdates: this.exdates,
188
+ rdates: this.rdates,
189
+ };
190
+ }
187
191
  }
188
192
  exports.RRuleSet = RRuleSet;
@@ -45,7 +45,7 @@ export interface RRuleOptions {
45
45
  readonly frequency: Frequency;
46
46
  readonly interval?: number;
47
47
  readonly count?: number;
48
- readonly until?: DateTime | DateTimeLike;
48
+ readonly until?: DateTime;
49
49
  readonly byWeekday?: readonly (NWeekday | Weekday)[];
50
50
  readonly byHour?: readonly number[];
51
51
  readonly byMinute?: readonly number[];
@@ -108,7 +108,8 @@ export declare class RRule {
108
108
  setByWeekno(weekNumbers: readonly number[]): RRule;
109
109
  setByYearday(days: readonly number[]): RRule;
110
110
  setWeekstart(day: Weekday): RRule;
111
- setUntil(datetime: DateTime | DateTimeLike): RRule;
111
+ setUntil(datetime: DateTime): RRule;
112
112
  toString(): string;
113
113
  toPlain(): RRuleLike;
114
+ private toOptions;
114
115
  }
@@ -82,7 +82,7 @@ class RRule {
82
82
  return new this({
83
83
  frequency: rrule.frequency,
84
84
  interval: rrule.interval,
85
- until: rrule.until,
85
+ until: rrule.until && datetime_1.DateTime.fromPlain(rrule.until),
86
86
  count: rrule.count,
87
87
  byWeekday: rrule.byWeekday,
88
88
  byHour: rrule.byHour,
@@ -119,53 +119,47 @@ class RRule {
119
119
  rrule.rust = rust;
120
120
  return rrule;
121
121
  }
122
- /**
123
- * @internal
124
- */
125
- static fromPlainOrInstance(rrule) {
126
- return rrule instanceof RRule ? rrule : this.fromPlain(rrule);
127
- }
128
122
  setFrequency(frequency) {
129
- return new RRule({ ...this.toPlain(), frequency });
123
+ return new RRule({ ...this.toOptions(), frequency });
130
124
  }
131
125
  setInterval(interval) {
132
- return new RRule({ ...this.toPlain(), interval });
126
+ return new RRule({ ...this.toOptions(), interval });
133
127
  }
134
128
  setCount(count) {
135
- return new RRule({ ...this.toPlain(), count });
129
+ return new RRule({ ...this.toOptions(), count });
136
130
  }
137
131
  setByWeekday(weekdays) {
138
- return new RRule({ ...this.toPlain(), byWeekday: weekdays });
132
+ return new RRule({ ...this.toOptions(), byWeekday: weekdays });
139
133
  }
140
134
  setByHour(hours) {
141
- return new RRule({ ...this.toPlain(), byHour: hours });
135
+ return new RRule({ ...this.toOptions(), byHour: hours });
142
136
  }
143
137
  setByMinute(minutes) {
144
- return new RRule({ ...this.toPlain(), byMinute: minutes });
138
+ return new RRule({ ...this.toOptions(), byMinute: minutes });
145
139
  }
146
140
  setBySecond(seconds) {
147
- return new RRule({ ...this.toPlain(), bySecond: seconds });
141
+ return new RRule({ ...this.toOptions(), bySecond: seconds });
148
142
  }
149
143
  setByMonthday(days) {
150
- return new RRule({ ...this.toPlain(), byMonthday: days });
144
+ return new RRule({ ...this.toOptions(), byMonthday: days });
151
145
  }
152
146
  setBySetpos(poses) {
153
- return new RRule({ ...this.toPlain(), bySetpos: poses });
147
+ return new RRule({ ...this.toOptions(), bySetpos: poses });
154
148
  }
155
149
  setByMonth(months) {
156
- return new RRule({ ...this.toPlain(), byMonth: months });
150
+ return new RRule({ ...this.toOptions(), byMonth: months });
157
151
  }
158
152
  setByWeekno(weekNumbers) {
159
- return new RRule({ ...this.toPlain(), byWeekno: weekNumbers });
153
+ return new RRule({ ...this.toOptions(), byWeekno: weekNumbers });
160
154
  }
161
155
  setByYearday(days) {
162
- return new RRule({ ...this.toPlain(), byYearday: days });
156
+ return new RRule({ ...this.toOptions(), byYearday: days });
163
157
  }
164
158
  setWeekstart(day) {
165
- return new RRule({ ...this.toPlain(), weekstart: day });
159
+ return new RRule({ ...this.toOptions(), weekstart: day });
166
160
  }
167
161
  setUntil(datetime) {
168
- return new RRule({ ...this.toPlain(), until: datetime });
162
+ return new RRule({ ...this.toOptions(), until: datetime });
169
163
  }
170
164
  toString() {
171
165
  return this.toRust().toString();
@@ -195,5 +189,23 @@ class RRule {
195
189
  until: this.until?.toPlain(),
196
190
  };
197
191
  }
192
+ toOptions() {
193
+ return {
194
+ frequency: this.frequency,
195
+ interval: this.interval,
196
+ count: this.count,
197
+ byWeekday: this.byWeekday,
198
+ byHour: this.byHour,
199
+ byMinute: this.byMinute,
200
+ bySecond: this.bySecond,
201
+ byMonthday: this.byMonthday,
202
+ bySetpos: this.bySetpos,
203
+ byMonth: this.byMonth,
204
+ byWeekno: this.byWeekno,
205
+ byYearday: this.byYearday,
206
+ weekstart: this.weekstart,
207
+ until: this.until,
208
+ };
209
+ }
198
210
  }
199
211
  exports.RRule = RRule;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rrule-rust",
3
- "version": "3.0.0-alpha.4",
3
+ "version": "3.0.0-alpha.6",
4
4
  "main": "dist/node/index.js",
5
5
  "browser": "dist/browser/index.js",
6
6
  "keywords": [
@@ -96,19 +96,19 @@
96
96
  "prepublishOnly": "npm run build && napi prepublish -t npm"
97
97
  },
98
98
  "optionalDependencies": {
99
- "@rrule-rust/lib-win32-x64-msvc": "3.0.0-alpha.4",
100
- "@rrule-rust/lib-darwin-x64": "3.0.0-alpha.4",
101
- "@rrule-rust/lib-linux-x64-gnu": "3.0.0-alpha.4",
102
- "@rrule-rust/lib-linux-x64-musl": "3.0.0-alpha.4",
103
- "@rrule-rust/lib-linux-arm64-gnu": "3.0.0-alpha.4",
104
- "@rrule-rust/lib-win32-ia32-msvc": "3.0.0-alpha.4",
105
- "@rrule-rust/lib-linux-arm-gnueabihf": "3.0.0-alpha.4",
106
- "@rrule-rust/lib-darwin-arm64": "3.0.0-alpha.4",
107
- "@rrule-rust/lib-android-arm64": "3.0.0-alpha.4",
108
- "@rrule-rust/lib-freebsd-x64": "3.0.0-alpha.4",
109
- "@rrule-rust/lib-linux-arm64-musl": "3.0.0-alpha.4",
110
- "@rrule-rust/lib-win32-arm64-msvc": "3.0.0-alpha.4",
111
- "@rrule-rust/lib-android-arm-eabi": "3.0.0-alpha.4",
112
- "@rrule-rust/lib-wasm32-wasi": "3.0.0-alpha.4"
99
+ "@rrule-rust/lib-win32-x64-msvc": "3.0.0-alpha.6",
100
+ "@rrule-rust/lib-darwin-x64": "3.0.0-alpha.6",
101
+ "@rrule-rust/lib-linux-x64-gnu": "3.0.0-alpha.6",
102
+ "@rrule-rust/lib-linux-x64-musl": "3.0.0-alpha.6",
103
+ "@rrule-rust/lib-linux-arm64-gnu": "3.0.0-alpha.6",
104
+ "@rrule-rust/lib-win32-ia32-msvc": "3.0.0-alpha.6",
105
+ "@rrule-rust/lib-linux-arm-gnueabihf": "3.0.0-alpha.6",
106
+ "@rrule-rust/lib-darwin-arm64": "3.0.0-alpha.6",
107
+ "@rrule-rust/lib-android-arm64": "3.0.0-alpha.6",
108
+ "@rrule-rust/lib-freebsd-x64": "3.0.0-alpha.6",
109
+ "@rrule-rust/lib-linux-arm64-musl": "3.0.0-alpha.6",
110
+ "@rrule-rust/lib-win32-arm64-msvc": "3.0.0-alpha.6",
111
+ "@rrule-rust/lib-android-arm-eabi": "3.0.0-alpha.6",
112
+ "@rrule-rust/lib-wasm32-wasi": "3.0.0-alpha.6"
113
113
  }
114
114
  }