rrule-rust 3.0.0-alpha.5 → 3.0.0-alpha.7

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
 
@@ -1,3 +1,8 @@
1
+ export interface DateLike {
2
+ readonly year: number;
3
+ readonly month: number;
4
+ readonly day: number;
5
+ }
1
6
  export interface DateTimeLike {
2
7
  readonly year: number;
3
8
  readonly month: number;
@@ -7,55 +12,64 @@ export interface DateTimeLike {
7
12
  readonly second: number;
8
13
  readonly utc: boolean;
9
14
  }
10
- export type DateTimeLikeWithoutUtc = Omit<DateTimeLike, 'utc'>;
11
- export interface ToPlainOptions {
15
+ export interface Time {
16
+ readonly hour: number;
17
+ readonly minute: number;
18
+ readonly second: number;
19
+ readonly utc: boolean;
20
+ }
21
+ export interface ToPlainDateTimeOptions {
12
22
  stripUtc?: boolean;
13
23
  }
14
24
  /**
15
25
  * Represents a date and time. Either local or UTC.
16
26
  */
17
- export declare class DateTime implements DateTimeLike {
18
- private readonly numeric;
27
+ export declare class DateTime<T extends Time | undefined> {
28
+ private readonly state;
19
29
  private constructor();
20
30
  get year(): number;
21
31
  get month(): number;
22
32
  get day(): number;
23
- get hour(): number;
24
- get minute(): number;
25
- get second(): number;
26
- get utc(): boolean;
33
+ get time(): T;
34
+ /**
35
+ * Creates a new DateTime object from the given date and time components.
36
+ */
37
+ static create(year: number, month: number, day: number): DateTime<undefined>;
38
+ static create(year: number, month: number, day: number, hour: number, minute: number, second: number, utc: boolean): DateTime<Time>;
27
39
  /**
28
40
  * Creates a new DateTime object from the given date and time components.
29
41
  */
30
- static create(year: number, month: number, day: number, hour: number, minute: number, second: number, utc: boolean): DateTime;
42
+ static date(year: number, month: number, day: number): DateTime<undefined>;
31
43
  /**
32
44
  * This method is shorthand for `DateTime.create` with `utc` set to `false`.
33
45
  */
34
- static local(year: number, month: number, day: number, hour: number, minute: number, second: number): DateTime;
46
+ static local(year: number, month: number, day: number, hour: number, minute: number, second: number): DateTime<Time>;
35
47
  /**
36
48
  * This method is shorthand for `DateTime.create` with `utc` set to `true`.
37
49
  */
38
- static utc(year: number, month: number, day: number, hour: number, minute: number, second: number): DateTime;
50
+ static utc(year: number, month: number, day: number, hour: number, minute: number, second: number): DateTime<Time>;
39
51
  /**
40
52
  * Creates a new DateTime object from the given plain object.
41
53
  */
42
- static fromPlain(plain: DateTimeLike): DateTime;
54
+ static fromPlain(plain: DateTimeLike): DateTime<Time>;
55
+ static fromPlain(plain: DateLike): DateTime<undefined>;
43
56
  /**
44
57
  * Creates a new DateTime object from provided string representation of a date according to RFC 5545.
45
58
  */
46
- static fromString(str: string): DateTime;
59
+ static fromString(str: string): DateTime<Time> | DateTime<undefined>;
47
60
  /**
48
61
  * Converts DateTime into a plain object.
49
62
  */
50
- toPlain(options: {
63
+ toPlain<DTL extends DateTimeLike>(options?: ToPlainDateTimeOptions & {
51
64
  stripUtc: false;
52
- } & ToPlainOptions): DateTimeLike;
53
- toPlain(options: {
65
+ }): DTL;
66
+ toPlain<DTL extends Omit<DateTimeLike, 'utc'>>(options?: ToPlainDateTimeOptions & {
54
67
  stripUtc: true;
55
- } & ToPlainOptions): DateTimeLikeWithoutUtc;
56
- toPlain(): DateTimeLike;
68
+ }): DTL;
69
+ toPlain<DTL extends DateLike>(): DTL;
57
70
  /**
58
71
  * Converts DateTime into ISO 8601 string:
72
+ * * `YYYYMMDD` for date only
59
73
  * - `YYYYMMDDTHHMMSSZ` for UTC
60
74
  * - `YYYYMMDDTHHMMSS` for local
61
75
  */
@@ -3,41 +3,64 @@
3
3
  */
4
4
  export class DateTime {
5
5
  constructor(numeric) {
6
- this.numeric = numeric;
6
+ this.state = {
7
+ numeric,
8
+ };
7
9
  }
8
10
  get year() {
9
- return Math.floor(this.numeric / 100000000000);
11
+ return (this.state.year ??= Math.floor(this.state.numeric / 100000000000));
10
12
  }
11
13
  get month() {
12
- return Math.floor((this.numeric / 1000000000) % 100);
14
+ return (this.state.month ??= Math.floor((this.state.numeric / 1000000000) % 100));
13
15
  }
14
16
  get day() {
15
- return Math.floor((this.numeric / 10000000) % 100);
16
- }
17
- get hour() {
18
- return Math.floor((this.numeric / 100000) % 100);
19
- }
20
- get minute() {
21
- return Math.floor((this.numeric / 1000) % 100);
17
+ return (this.state.day ??= Math.floor((this.state.numeric / 10000000) % 100));
22
18
  }
23
- get second() {
24
- return Math.floor((this.numeric / 10) % 100);
19
+ get time() {
20
+ // return cached time if available
21
+ if ('time' in this.state) {
22
+ return this.state.time;
23
+ }
24
+ const type = this.state.numeric % 10; // 0 – non utc, 1 – utc, 2 – date only
25
+ if (type == 2) {
26
+ // if it's date only, return undefined and cache it in state
27
+ return (this.state.time ??= undefined);
28
+ }
29
+ else {
30
+ // otherwise compute it from numeric representation and cache it in state
31
+ return (this.state.time ??= {
32
+ hour: Math.floor((this.state.numeric / 100000) % 100),
33
+ minute: Math.floor((this.state.numeric / 1000) % 100),
34
+ second: Math.floor((this.state.numeric / 10) % 100),
35
+ utc: this.state.numeric % 10 == 1,
36
+ });
37
+ }
25
38
  }
26
- get utc() {
27
- return this.numeric % 10 == 1;
39
+ static create(year, month, day, hour, minute, second, utc) {
40
+ let numeric = year * 100000000000 + month * 1000000000 + day * 10000000;
41
+ if (hour !== undefined &&
42
+ minute !== undefined &&
43
+ second !== undefined &&
44
+ utc !== undefined) {
45
+ numeric += hour * 100000;
46
+ numeric += minute * 1000;
47
+ numeric += second * 10;
48
+ numeric += utc ? 1 : 0;
49
+ return new DateTime(numeric);
50
+ }
51
+ else {
52
+ numeric += 100000;
53
+ numeric += 1000;
54
+ numeric += 10;
55
+ numeric += 2;
56
+ return new DateTime(numeric);
57
+ }
28
58
  }
29
59
  /**
30
60
  * Creates a new DateTime object from the given date and time components.
31
61
  */
32
- static create(year, month, day, hour, minute, second, utc) {
33
- const numeric = year * 100000000000 +
34
- month * 1000000000 +
35
- day * 10000000 +
36
- hour * 100000 +
37
- minute * 1000 +
38
- second * 10 +
39
- (utc ? 1 : 0);
40
- return new DateTime(numeric);
62
+ static date(year, month, day) {
63
+ return this.create(year, month, day);
41
64
  }
42
65
  /**
43
66
  * This method is shorthand for `DateTime.create` with `utc` set to `false`.
@@ -51,68 +74,101 @@ export class DateTime {
51
74
  static utc(year, month, day, hour, minute, second) {
52
75
  return DateTime.create(year, month, day, hour, minute, second, true);
53
76
  }
54
- /**
55
- * Creates a new DateTime object from the given plain object.
56
- */
57
77
  static fromPlain(plain) {
58
- return DateTime.create(plain.year, plain.month, plain.day, plain.hour, plain.minute, plain.second, plain.utc);
78
+ if ('hour' in plain) {
79
+ return DateTime.create(plain.year, plain.month, plain.day, plain.hour, plain.minute, plain.second, plain.utc);
80
+ }
81
+ return DateTime.create(plain.year, plain.month, plain.day);
59
82
  }
60
83
  /**
61
84
  * Creates a new DateTime object from provided string representation of a date according to RFC 5545.
62
85
  */
86
+ // TODO: add template expression
63
87
  static fromString(str) {
64
- const typeError = new TypeError('Invalid date time string');
65
- if (str.length > 16 || str.length < 15) {
66
- throw typeError;
88
+ if (!(str.length === 8 || (str.length <= 16 && str.length >= 15))) {
89
+ throw new TypeError('Invalid date time string');
67
90
  }
68
91
  const year = parseInt(str.slice(0, 4));
69
92
  const month = parseInt(str.slice(4, 6));
70
93
  const day = parseInt(str.slice(6, 8));
71
- const hour = parseInt(str.slice(9, 11));
72
- const minute = parseInt(str.slice(11, 13));
73
- const second = parseInt(str.slice(13, 15));
74
- const utc = str.endsWith('Z');
75
- if (isNaN(year) ||
76
- isNaN(month) ||
77
- isNaN(day) ||
78
- isNaN(hour) ||
79
- isNaN(minute) ||
80
- isNaN(second)) {
81
- throw typeError;
94
+ let hour = undefined;
95
+ let minute = undefined;
96
+ let second = undefined;
97
+ let utc = undefined;
98
+ if (isNaN(year) || isNaN(month) || isNaN(day)) {
99
+ throw new TypeError('Invalid date');
100
+ }
101
+ if (str.length > 8) {
102
+ hour = parseInt(str.slice(9, 11));
103
+ minute = parseInt(str.slice(11, 13));
104
+ second = parseInt(str.slice(13, 15));
105
+ utc = str.endsWith('Z');
106
+ if (isNaN(hour) || isNaN(minute) || isNaN(second)) {
107
+ throw new TypeError('Invalid time');
108
+ }
109
+ return DateTime.create(year, month, day, hour, minute, second, utc);
110
+ }
111
+ else {
112
+ return DateTime.create(year, month, day);
82
113
  }
83
- return DateTime.create(year, month, day, hour, minute, second, utc);
84
114
  }
85
115
  /** @internal */
86
116
  static fromNumeric(numeric) {
87
117
  return new DateTime(numeric);
88
118
  }
89
119
  toPlain(options) {
90
- return {
91
- year: this.year,
92
- month: this.month,
93
- day: this.day,
94
- hour: this.hour,
95
- minute: this.minute,
96
- second: this.second,
97
- utc: options?.stripUtc ? undefined : this.utc,
98
- };
120
+ let plain;
121
+ if (this.time) {
122
+ plain = options?.stripUtc
123
+ ? {
124
+ year: this.year,
125
+ month: this.month,
126
+ day: this.day,
127
+ hour: this.time.hour,
128
+ minute: this.time.minute,
129
+ second: this.time.second,
130
+ }
131
+ : {
132
+ year: this.year,
133
+ month: this.month,
134
+ day: this.day,
135
+ hour: this.time.hour,
136
+ minute: this.time.minute,
137
+ second: this.time.second,
138
+ utc: this.time.utc,
139
+ };
140
+ }
141
+ else {
142
+ plain = {
143
+ year: this.year,
144
+ month: this.month,
145
+ day: this.day,
146
+ };
147
+ }
148
+ return plain;
99
149
  }
100
150
  /**
101
151
  * Converts DateTime into ISO 8601 string:
152
+ * * `YYYYMMDD` for date only
102
153
  * - `YYYYMMDDTHHMMSSZ` for UTC
103
154
  * - `YYYYMMDDTHHMMSS` for local
104
155
  */
105
156
  toString() {
106
- const year = this.year.toString().padStart(4, '0');
107
- const month = this.month.toString().padStart(2, '0');
108
- const day = this.day.toString().padStart(2, '0');
109
- const hour = this.hour.toString().padStart(2, '0');
110
- const minute = this.minute.toString().padStart(2, '0');
111
- const second = this.second.toString().padStart(2, '0');
112
- return `${year}${month}${day}T${hour}${minute}${second}${this.utc ? 'Z' : ''}`;
157
+ let str = this.year.toString().padStart(4, '0') +
158
+ this.month.toString().padStart(2, '0') +
159
+ this.day.toString().padStart(2, '0');
160
+ if (this.time) {
161
+ str +=
162
+ 'T' +
163
+ this.time.hour.toString().padStart(2, '0') +
164
+ this.time.minute.toString().padStart(2, '0') +
165
+ this.time.second.toString().padStart(2, '0') +
166
+ (this.time.utc ? 'Z' : '');
167
+ }
168
+ return str;
113
169
  }
114
170
  /** @internal */
115
171
  toNumeric() {
116
- return this.numeric;
172
+ return this.state.numeric;
117
173
  }
118
174
  }
@@ -0,0 +1,20 @@
1
+ import { DateTime, type Time, type DateTimeLike, type DateLike } from './datetime';
2
+ export interface DtStartOptions<DT extends DateTime<Time> | DateTime<undefined>> {
3
+ datetime: DT;
4
+ tzid?: string;
5
+ }
6
+ export interface DtStartLike<DT extends DateTimeLike | DateLike> {
7
+ datetime: DT;
8
+ tzid?: string;
9
+ }
10
+ export declare class DtStart<DT extends DateTime<Time> | DateTime<undefined> = DateTime<Time>> {
11
+ readonly datetime: DT;
12
+ readonly tzid?: string;
13
+ constructor(datetime: DateTime<Time> | DateTime<undefined>, tzid?: string);
14
+ constructor(options: DtStartOptions<DT>);
15
+ static fromPlain(plain: DtStartLike<DateTimeLike>): DtStart<DateTime<Time>>;
16
+ static fromPlain(plain: DtStartLike<DateLike>): DtStart<DateTime<undefined>>;
17
+ setTzid(tzid: string | undefined): DtStart<DT>;
18
+ setDatetime<NDT extends DateTime<Time> | DateTime<undefined>>(datetime: NDT): DtStart<NDT>;
19
+ toPlain<DTL extends DateTimeLike | DateLike = DT extends DateTime<Time> ? DateTimeLike : DateLike>(): DtStartLike<DTL>;
20
+ }
@@ -0,0 +1,31 @@
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(this.datetime, tzid);
21
+ }
22
+ setDatetime(datetime) {
23
+ return new DtStart(datetime, this.tzid);
24
+ }
25
+ toPlain() {
26
+ return {
27
+ datetime: this.datetime.toPlain(),
28
+ tzid: this.tzid,
29
+ };
30
+ }
31
+ }
@@ -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,51 +1,49 @@
1
1
  import { RRule, type RRuleLike } from './rrule';
2
- import { DateTime, type DateTimeLike } from './datetime';
3
- export interface RRuleSetOptions {
4
- readonly dtstart: DateTime;
5
- readonly tzid?: string;
6
- readonly rrules?: readonly RRule[];
7
- readonly exrules?: readonly RRule[];
8
- readonly exdates?: readonly DateTime[];
9
- readonly rdates?: readonly DateTime[];
2
+ import { type Time, DateTime, type DateTimeLike, type DateLike } from './datetime';
3
+ import { DtStart, type DtStartLike } from './dtstart';
4
+ export interface RRuleSetOptions<DT extends DateTime<Time> | DateTime<undefined> = DateTime<Time>> {
5
+ readonly dtstart: DtStart<DT>;
6
+ readonly rrules?: readonly RRule<DT>[];
7
+ readonly exrules?: readonly RRule<DT>[];
8
+ readonly exdates?: readonly DT[];
9
+ readonly rdates?: readonly DT[];
10
10
  }
11
- export interface RRuleSetLike {
12
- readonly dtstart: DateTimeLike;
13
- readonly tzid?: string;
14
- readonly rrules: readonly RRuleLike[];
15
- readonly exrules: readonly RRuleLike[];
16
- readonly exdates: readonly DateTimeLike[];
17
- readonly rdates: readonly DateTimeLike[];
11
+ export interface RRuleSetLike<DT extends DateTimeLike | DateLike> {
12
+ readonly dtstart: DtStartLike<DT>;
13
+ readonly rrules: readonly RRuleLike<DT>[];
14
+ readonly exrules: readonly RRuleLike<DT>[];
15
+ readonly exdates: readonly DT[];
16
+ readonly rdates: readonly DT[];
18
17
  }
19
- export declare class RRuleSet implements Iterable<DateTime> {
20
- readonly dtstart: DateTime;
21
- readonly tzid: string;
22
- readonly rrules: readonly RRule[];
23
- readonly exrules: readonly RRule[];
24
- readonly exdates: readonly DateTime[];
25
- readonly rdates: readonly DateTime[];
26
- constructor(dtstart: DateTime | DateTimeLike, tzid?: string);
27
- constructor(options: RRuleSetOptions);
18
+ export declare class RRuleSet<DT extends DateTime<Time> | DateTime<undefined>> implements Iterable<DateTime<Time> | DateTime<undefined>> {
19
+ readonly dtstart: DtStart<DT>;
20
+ readonly rrules: readonly RRule<DT>[];
21
+ readonly exrules: readonly RRule<DT>[];
22
+ readonly exdates: readonly DT[];
23
+ readonly rdates: readonly DT[];
24
+ constructor(dtstart: DtStart<DT>);
25
+ constructor(options: RRuleSetOptions<DT>);
28
26
  /**
29
27
  * Parses a string into an RRuleSet.
30
28
  */
31
- static parse(str: string): RRuleSet;
32
- static fromPlain(plain: RRuleSetLike): RRuleSet;
33
- setDtstart(dtstart: DateTime): RRuleSet;
34
- setTzid(tzid: string): RRuleSet;
35
- addRrule(rrule: RRule): RRuleSet;
36
- setRrules(rrules: readonly RRule[]): RRuleSet;
37
- addExrule(rrule: RRule): RRuleSet;
38
- setExrules(rrules: readonly RRule[]): RRuleSet;
39
- addExdate(datetime: DateTime): RRuleSet;
40
- setExdates(datetimes: readonly DateTime[]): RRuleSet;
41
- addRdate(datetime: DateTime): RRuleSet;
42
- setRdates(datetimes: readonly DateTime[]): RRuleSet;
29
+ static parse<DT extends DateTime<Time> | DateTime<undefined>>(str: string): RRuleSet<DT>;
30
+ static fromPlain(plain: RRuleSetLike<DateTimeLike>): RRuleSet<DateTime<Time>>;
31
+ static fromPlain(plain: RRuleSetLike<DateLike>): RRuleSet<DateTime<undefined>>;
32
+ setDtstart(dtstart: DtStart<DT>): RRuleSet<DT>;
33
+ addRrule<RRDT extends DT>(rrule: RRule<RRDT>): RRuleSet<DT>;
34
+ setRrules(rrules: readonly RRule<DT>[]): RRuleSet<DT>;
35
+ addExrule(rrule: RRule<DT>): RRuleSet<DT>;
36
+ setExrules(rrules: readonly RRule<DT>[]): RRuleSet<DT>;
37
+ addExdate(datetime: DT): RRuleSet<DT>;
38
+ setExdates(datetimes: readonly DT[]): RRuleSet<DT>;
39
+ addRdate(datetime: DT): RRuleSet<DT>;
40
+ setRdates(datetimes: readonly DT[]): RRuleSet<DT>;
43
41
  /**
44
42
  * Returns all the occurrences of the rrule.
45
43
  *
46
44
  * @param limit - The maximum number of occurrences to return.
47
45
  */
48
- all(limit?: number): DateTime[];
46
+ all(limit?: number): DT[];
49
47
  /**
50
48
  * Returns all the occurrences of the rrule between after and before.
51
49
  *
@@ -53,18 +51,18 @@ export declare class RRuleSet implements Iterable<DateTime> {
53
51
  * @param before - The upper bound date.
54
52
  * @param inclusive - Whether to include after and before in the list of occurrences.
55
53
  */
56
- between(after: DateTime, before: DateTime, inclusive?: boolean): DateTime[];
54
+ between(after: DT, before: DT, inclusive?: boolean): DT[];
57
55
  /**
58
56
  * Sets the RRuleSet from a string.
59
57
  *
60
58
  * @param str - The string to parse.
61
59
  */
62
- setFromString(str: string): RRuleSet;
60
+ setFromString<NDT extends DateTime<Time> | DateTime<undefined> = DT>(str: string): RRuleSet<NDT>;
63
61
  toString(): string;
64
62
  /**
65
63
  * Converts the RRuleSet to a plain object.
66
64
  */
67
- toPlain(): RRuleSetLike;
68
- [Symbol.iterator](): Iterator<DateTime, any, any>;
65
+ toPlain(): RRuleSetLike<DT extends DateTime<Time> ? DateTimeLike : DateLike>;
66
+ [Symbol.iterator](): Iterator<DT, any, any>;
69
67
  private toOptions;
70
68
  }
@@ -1,41 +1,33 @@
1
1
  import { RRule } from './rrule';
2
2
  import { RRuleSet as Rust } from './lib';
3
- import { DateTime } from './datetime';
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) {
6
+ constructor(optionsOrDtstart) {
7
+ if ('dtstart' in optionsOrDtstart) {
9
8
  this.dtstart = optionsOrDtstart.dtstart;
10
- this.tzid = optionsOrDtstart.tzid ?? 'UTC';
11
9
  this.rrules = optionsOrDtstart?.rrules ?? [];
12
10
  this.exrules = optionsOrDtstart?.exrules ?? [];
13
11
  this.exdates = optionsOrDtstart?.exdates ?? [];
14
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.
30
24
  */
31
25
  static parse(str) {
32
- const rust = Rust.parse(str);
33
- return this.fromRust(rust);
26
+ return this.fromRust(Rust.parse(str));
34
27
  }
35
28
  static fromPlain(plain) {
36
29
  return new RRuleSet({
37
- dtstart: DateTime.fromPlain(plain.dtstart),
38
- tzid: plain.tzid,
30
+ dtstart: DtStart.fromPlain(plain.dtstart),
39
31
  rrules: plain.rrules.map((rrule) => RRule.fromPlain(rrule)),
40
32
  exrules: plain.exrules.map((rrule) => RRule.fromPlain(rrule)),
41
33
  exdates: plain.exdates.map((datetime) => DateTime.fromPlain(datetime)),
@@ -47,8 +39,10 @@ export class RRuleSet {
47
39
  */
48
40
  static fromRust(rust) {
49
41
  const set = new RRuleSet({
50
- dtstart: DateTime.fromNumeric(rust.dtstart),
51
- tzid: rust.tzid ?? undefined,
42
+ dtstart: new DtStart({
43
+ datetime: DateTime.fromNumeric(rust.dtstart),
44
+ tzid: rust.tzid ?? undefined,
45
+ }),
52
46
  rrules: rust.rrules.map((rrule) => RRule.fromRust(rrule)),
53
47
  exrules: rust.exrules.map((rrule) => RRule.fromRust(rrule)),
54
48
  exdates: rust.exdates.map((datetime) => DateTime.fromNumeric(datetime)),
@@ -63,12 +57,6 @@ export class RRuleSet {
63
57
  dtstart: dtstart,
64
58
  });
65
59
  }
66
- setTzid(tzid) {
67
- return new RRuleSet({
68
- ...this.toOptions(),
69
- tzid: tzid,
70
- });
71
- }
72
60
  addRrule(rrule) {
73
61
  return new RRuleSet({
74
62
  ...this.toOptions(),
@@ -151,7 +139,7 @@ export class RRuleSet {
151
139
  * @internal
152
140
  */
153
141
  toRust() {
154
- 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()));
142
+ this.rust ??= new Rust(this.dtstart.datetime.toNumeric(), this.dtstart.tzid, undefined, this.rrules.map((rrule) => rrule.toRust()), this.exrules.map((rrule) => rrule.toRust()), this.exdates.map((datetime) => datetime.toNumeric()), this.rdates.map((datetime) => datetime.toNumeric()));
155
143
  return this.rust;
156
144
  }
157
145
  toString() {
@@ -163,7 +151,6 @@ export class RRuleSet {
163
151
  toPlain() {
164
152
  return {
165
153
  dtstart: this.dtstart.toPlain(),
166
- tzid: this.tzid,
167
154
  rrules: this.rrules.map((rrule) => rrule.toPlain()),
168
155
  exrules: this.exrules.map((rrule) => rrule.toPlain()),
169
156
  exdates: this.exdates.map((rrule) => rrule.toPlain()),
@@ -191,7 +178,6 @@ export class RRuleSet {
191
178
  toOptions() {
192
179
  return {
193
180
  dtstart: this.dtstart,
194
- tzid: this.tzid,
195
181
  rrules: this.rrules,
196
182
  exrules: this.exrules,
197
183
  exdates: this.exdates,