rrule-rust 3.0.0-alpha.3 → 3.0.0-alpha.4
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/dist/browser/datetime.d.ts +12 -4
- package/dist/browser/datetime.js +8 -6
- package/dist/browser/rrule-set.d.ts +28 -19
- package/dist/browser/rrule-set.js +32 -33
- package/dist/browser/rrule.d.ts +22 -5
- package/dist/browser/rrule.js +59 -33
- package/dist/node/datetime.d.ts +12 -4
- package/dist/node/datetime.js +8 -6
- package/dist/node/rrule-set.d.ts +28 -19
- package/dist/node/rrule-set.js +32 -33
- package/dist/node/rrule.d.ts +22 -5
- package/dist/node/rrule.js +59 -33
- package/package.json +15 -15
|
@@ -5,9 +5,11 @@ export interface DateTimeLike {
|
|
|
5
5
|
readonly hour: number;
|
|
6
6
|
readonly minute: number;
|
|
7
7
|
readonly second: number;
|
|
8
|
+
readonly utc: boolean;
|
|
8
9
|
}
|
|
9
|
-
export
|
|
10
|
-
|
|
10
|
+
export type DateTimeLikeWithoutUtc = Omit<DateTimeLike, 'utc'>;
|
|
11
|
+
export interface ToPlainOptions {
|
|
12
|
+
stripUtc?: boolean;
|
|
11
13
|
}
|
|
12
14
|
/**
|
|
13
15
|
* Represents a date and time. Either local or UTC.
|
|
@@ -37,7 +39,7 @@ export declare class DateTime implements DateTimeLike {
|
|
|
37
39
|
/**
|
|
38
40
|
* Creates a new DateTime object from the given plain object.
|
|
39
41
|
*/
|
|
40
|
-
static
|
|
42
|
+
static fromPlain(plain: DateTimeLike): DateTime;
|
|
41
43
|
/**
|
|
42
44
|
* Creates a new DateTime object from provided string representation of a date according to RFC 5545.
|
|
43
45
|
*/
|
|
@@ -45,7 +47,13 @@ export declare class DateTime implements DateTimeLike {
|
|
|
45
47
|
/**
|
|
46
48
|
* Converts DateTime into a plain object.
|
|
47
49
|
*/
|
|
48
|
-
|
|
50
|
+
toPlain(options: {
|
|
51
|
+
stripUtc: false;
|
|
52
|
+
} & ToPlainOptions): DateTimeLike;
|
|
53
|
+
toPlain(options: {
|
|
54
|
+
stripUtc: true;
|
|
55
|
+
} & ToPlainOptions): DateTimeLikeWithoutUtc;
|
|
56
|
+
toPlain(): DateTimeLike;
|
|
49
57
|
/**
|
|
50
58
|
* Converts DateTime into ISO 8601 string:
|
|
51
59
|
* - `YYYYMMDDTHHMMSSZ` for UTC
|
package/dist/browser/datetime.js
CHANGED
|
@@ -54,8 +54,8 @@ export class DateTime {
|
|
|
54
54
|
/**
|
|
55
55
|
* Creates a new DateTime object from the given plain object.
|
|
56
56
|
*/
|
|
57
|
-
static
|
|
58
|
-
return DateTime.create(
|
|
57
|
+
static fromPlain(plain) {
|
|
58
|
+
return DateTime.create(plain.year, plain.month, plain.day, plain.hour, plain.minute, plain.second, plain.utc);
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
61
|
* Creates a new DateTime object from provided string representation of a date according to RFC 5545.
|
|
@@ -86,10 +86,11 @@ export class DateTime {
|
|
|
86
86
|
static fromNumeric(numeric) {
|
|
87
87
|
return new DateTime(numeric);
|
|
88
88
|
}
|
|
89
|
-
/**
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
/** @internal */
|
|
90
|
+
static fromPlainOrInstance(datetime) {
|
|
91
|
+
return datetime instanceof DateTime ? datetime : this.fromPlain(datetime);
|
|
92
|
+
}
|
|
93
|
+
toPlain(options) {
|
|
93
94
|
return {
|
|
94
95
|
year: this.year,
|
|
95
96
|
month: this.month,
|
|
@@ -97,6 +98,7 @@ export class DateTime {
|
|
|
97
98
|
hour: this.hour,
|
|
98
99
|
minute: this.minute,
|
|
99
100
|
second: this.second,
|
|
101
|
+
utc: options?.stripUtc ? undefined : this.utc,
|
|
100
102
|
};
|
|
101
103
|
}
|
|
102
104
|
/**
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
import { RRule } from './rrule';
|
|
2
|
-
import { DateTime } from './datetime';
|
|
1
|
+
import { RRule, type RRuleLike } from './rrule';
|
|
2
|
+
import { DateTime, type DateTimeLike } from './datetime';
|
|
3
|
+
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)[];
|
|
10
|
+
}
|
|
3
11
|
export interface RRuleSetLike {
|
|
4
|
-
readonly dtstart:
|
|
12
|
+
readonly dtstart: DateTimeLike;
|
|
5
13
|
readonly tzid?: string;
|
|
6
|
-
readonly rrules: readonly
|
|
7
|
-
readonly exrules: readonly
|
|
8
|
-
readonly exdates: readonly
|
|
9
|
-
readonly rdates: readonly
|
|
14
|
+
readonly rrules: readonly RRuleLike[];
|
|
15
|
+
readonly exrules: readonly RRuleLike[];
|
|
16
|
+
readonly exdates: readonly DateTimeLike[];
|
|
17
|
+
readonly rdates: readonly DateTimeLike[];
|
|
10
18
|
}
|
|
11
19
|
export declare class RRuleSet implements Iterable<DateTime> {
|
|
12
20
|
readonly dtstart: DateTime;
|
|
@@ -15,22 +23,23 @@ export declare class RRuleSet implements Iterable<DateTime> {
|
|
|
15
23
|
readonly exrules: readonly RRule[];
|
|
16
24
|
readonly exdates: readonly DateTime[];
|
|
17
25
|
readonly rdates: readonly DateTime[];
|
|
18
|
-
constructor(dtstart: DateTime, tzid?: string);
|
|
19
|
-
constructor(options:
|
|
26
|
+
constructor(dtstart: DateTime | DateTimeLike, tzid?: string);
|
|
27
|
+
constructor(options: RRuleSetOptions);
|
|
20
28
|
/**
|
|
21
29
|
* Parses a string into an RRuleSet.
|
|
22
30
|
*/
|
|
23
31
|
static parse(str: string): RRuleSet;
|
|
24
|
-
|
|
32
|
+
static fromPlain(plain: RRuleSetLike): RRuleSet;
|
|
33
|
+
setDtstart(dtstart: DateTime | DateTimeLike): RRuleSet;
|
|
25
34
|
setTzid(tzid: string): RRuleSet;
|
|
26
|
-
addRrule(rrule: RRule): RRuleSet;
|
|
27
|
-
setRrules(rrules: readonly RRule[]): RRuleSet;
|
|
28
|
-
addExrule(rrule: RRule): RRuleSet;
|
|
29
|
-
setExrules(rrules: readonly RRule[]): RRuleSet;
|
|
30
|
-
addExdate(datetime: DateTime): RRuleSet;
|
|
31
|
-
setExdates(datetimes: readonly DateTime[]): RRuleSet;
|
|
32
|
-
addRdate(datetime: DateTime): RRuleSet;
|
|
33
|
-
setRdates(datetimes: readonly DateTime[]): 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;
|
|
34
43
|
/**
|
|
35
44
|
* Returns all the occurrences of the rrule.
|
|
36
45
|
*
|
|
@@ -55,6 +64,6 @@ export declare class RRuleSet implements Iterable<DateTime> {
|
|
|
55
64
|
/**
|
|
56
65
|
* Converts the RRuleSet to a plain object.
|
|
57
66
|
*/
|
|
58
|
-
|
|
67
|
+
toPlain(): RRuleSetLike;
|
|
59
68
|
[Symbol.iterator](): Iterator<DateTime, any, any>;
|
|
60
69
|
}
|
|
@@ -2,24 +2,20 @@ import { RRule } from './rrule';
|
|
|
2
2
|
import { RRuleSet as Rust } from './lib';
|
|
3
3
|
import { DateTime } from './datetime';
|
|
4
4
|
export class RRuleSet {
|
|
5
|
-
constructor(
|
|
6
|
-
if (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
this.
|
|
15
|
-
this.rrules = setOrDtstart?.rrules ?? [];
|
|
16
|
-
this.exrules = setOrDtstart?.exrules ?? [];
|
|
17
|
-
this.exdates = setOrDtstart?.exdates ?? [];
|
|
18
|
-
this.rdates = setOrDtstart?.rdates ?? [];
|
|
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));
|
|
19
15
|
}
|
|
20
|
-
else if (
|
|
21
|
-
this.dtstart =
|
|
22
|
-
this.tzid = tzid;
|
|
16
|
+
else if (optionsOrDtstart instanceof DateTime) {
|
|
17
|
+
this.dtstart = optionsOrDtstart;
|
|
18
|
+
this.tzid = tzid ?? 'UTC';
|
|
23
19
|
this.rrules = [];
|
|
24
20
|
this.exrules = [];
|
|
25
21
|
this.exdates = [];
|
|
@@ -36,6 +32,9 @@ export class RRuleSet {
|
|
|
36
32
|
const rust = Rust.parse(str);
|
|
37
33
|
return this.fromRust(rust);
|
|
38
34
|
}
|
|
35
|
+
static fromPlain(plain) {
|
|
36
|
+
return new RRuleSet(plain);
|
|
37
|
+
}
|
|
39
38
|
/**
|
|
40
39
|
* @internal
|
|
41
40
|
*/
|
|
@@ -53,61 +52,61 @@ export class RRuleSet {
|
|
|
53
52
|
}
|
|
54
53
|
setDtstart(dtstart) {
|
|
55
54
|
return new RRuleSet({
|
|
56
|
-
...this.
|
|
55
|
+
...this.toPlain(),
|
|
57
56
|
dtstart: dtstart,
|
|
58
57
|
});
|
|
59
58
|
}
|
|
60
59
|
setTzid(tzid) {
|
|
61
60
|
return new RRuleSet({
|
|
62
|
-
...this.
|
|
61
|
+
...this.toPlain(),
|
|
63
62
|
tzid: tzid,
|
|
64
63
|
});
|
|
65
64
|
}
|
|
66
65
|
addRrule(rrule) {
|
|
67
66
|
return new RRuleSet({
|
|
68
|
-
...this.
|
|
67
|
+
...this.toPlain(),
|
|
69
68
|
rrules: [...this.rrules, rrule],
|
|
70
69
|
});
|
|
71
70
|
}
|
|
72
71
|
setRrules(rrules) {
|
|
73
72
|
return new RRuleSet({
|
|
74
|
-
...this.
|
|
73
|
+
...this.toPlain(),
|
|
75
74
|
rrules: rrules,
|
|
76
75
|
});
|
|
77
76
|
}
|
|
78
77
|
addExrule(rrule) {
|
|
79
78
|
return new RRuleSet({
|
|
80
|
-
...this.
|
|
79
|
+
...this.toPlain(),
|
|
81
80
|
exrules: [...this.exrules, rrule],
|
|
82
81
|
});
|
|
83
82
|
}
|
|
84
83
|
setExrules(rrules) {
|
|
85
84
|
return new RRuleSet({
|
|
86
|
-
...this.
|
|
85
|
+
...this.toPlain(),
|
|
87
86
|
exrules: rrules,
|
|
88
87
|
});
|
|
89
88
|
}
|
|
90
89
|
addExdate(datetime) {
|
|
91
90
|
return new RRuleSet({
|
|
92
|
-
...this.
|
|
91
|
+
...this.toPlain(),
|
|
93
92
|
exdates: [...this.exdates, datetime],
|
|
94
93
|
});
|
|
95
94
|
}
|
|
96
95
|
setExdates(datetimes) {
|
|
97
96
|
return new RRuleSet({
|
|
98
|
-
...this.
|
|
97
|
+
...this.toPlain(),
|
|
99
98
|
exdates: datetimes,
|
|
100
99
|
});
|
|
101
100
|
}
|
|
102
101
|
addRdate(datetime) {
|
|
103
102
|
return new RRuleSet({
|
|
104
|
-
...this.
|
|
103
|
+
...this.toPlain(),
|
|
105
104
|
rdates: [...this.rdates, datetime],
|
|
106
105
|
});
|
|
107
106
|
}
|
|
108
107
|
setRdates(datetimes) {
|
|
109
108
|
return new RRuleSet({
|
|
110
|
-
...this.
|
|
109
|
+
...this.toPlain(),
|
|
111
110
|
rdates: datetimes,
|
|
112
111
|
});
|
|
113
112
|
}
|
|
@@ -154,14 +153,14 @@ export class RRuleSet {
|
|
|
154
153
|
/**
|
|
155
154
|
* Converts the RRuleSet to a plain object.
|
|
156
155
|
*/
|
|
157
|
-
|
|
156
|
+
toPlain() {
|
|
158
157
|
return {
|
|
159
|
-
dtstart: this.dtstart,
|
|
158
|
+
dtstart: this.dtstart.toPlain(),
|
|
160
159
|
tzid: this.tzid,
|
|
161
|
-
rrules: this.rrules,
|
|
162
|
-
exrules: this.exrules,
|
|
163
|
-
exdates: this.exdates,
|
|
164
|
-
rdates: this.rdates,
|
|
160
|
+
rrules: this.rrules.map((rrule) => rrule.toPlain()),
|
|
161
|
+
exrules: this.exrules.map((rrule) => rrule.toPlain()),
|
|
162
|
+
exdates: this.exdates.map((rrule) => rrule.toPlain()),
|
|
163
|
+
rdates: this.rdates.map((rrule) => rrule.toPlain()),
|
|
165
164
|
};
|
|
166
165
|
}
|
|
167
166
|
[Symbol.iterator]() {
|
package/dist/browser/rrule.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DateTime } from './datetime';
|
|
1
|
+
import { DateTime, type DateTimeLike } from './datetime';
|
|
2
2
|
export interface NWeekday {
|
|
3
3
|
/**
|
|
4
4
|
* If set, this represents the nth occurrence of the weekday.
|
|
@@ -41,11 +41,27 @@ export declare enum Weekday {
|
|
|
41
41
|
Saturday = 5,
|
|
42
42
|
Sunday = 6
|
|
43
43
|
}
|
|
44
|
+
export interface RRuleOptions {
|
|
45
|
+
readonly frequency: Frequency;
|
|
46
|
+
readonly interval?: number;
|
|
47
|
+
readonly count?: number;
|
|
48
|
+
readonly until?: DateTime | DateTimeLike;
|
|
49
|
+
readonly byWeekday?: readonly (NWeekday | Weekday)[];
|
|
50
|
+
readonly byHour?: readonly number[];
|
|
51
|
+
readonly byMinute?: readonly number[];
|
|
52
|
+
readonly bySecond?: readonly number[];
|
|
53
|
+
readonly byMonthday?: readonly number[];
|
|
54
|
+
readonly bySetpos?: readonly number[];
|
|
55
|
+
readonly byMonth?: readonly Month[];
|
|
56
|
+
readonly byWeekno?: readonly number[];
|
|
57
|
+
readonly byYearday?: readonly number[];
|
|
58
|
+
readonly weekstart?: Weekday;
|
|
59
|
+
}
|
|
44
60
|
export interface RRuleLike {
|
|
45
61
|
readonly frequency: Frequency;
|
|
46
62
|
readonly interval?: number;
|
|
47
63
|
readonly count?: number;
|
|
48
|
-
readonly until?:
|
|
64
|
+
readonly until?: DateTimeLike;
|
|
49
65
|
readonly byWeekday: readonly (NWeekday | Weekday)[];
|
|
50
66
|
readonly byHour: readonly number[];
|
|
51
67
|
readonly byMinute: readonly number[];
|
|
@@ -73,11 +89,12 @@ export declare class RRule {
|
|
|
73
89
|
readonly byYearday: readonly number[];
|
|
74
90
|
readonly weekstart?: Weekday;
|
|
75
91
|
constructor(frequency: Frequency);
|
|
76
|
-
constructor(
|
|
92
|
+
constructor(options: RRuleOptions);
|
|
77
93
|
/**
|
|
78
94
|
* Parses a string into an RRule.
|
|
79
95
|
*/
|
|
80
96
|
static parse(str: string): RRule;
|
|
97
|
+
static fromPlain(rrule: RRuleLike): RRule;
|
|
81
98
|
setFrequency(frequency: Frequency): RRule;
|
|
82
99
|
setInterval(interval: number): RRule;
|
|
83
100
|
setCount(count: number): RRule;
|
|
@@ -91,7 +108,7 @@ export declare class RRule {
|
|
|
91
108
|
setByWeekno(weekNumbers: readonly number[]): RRule;
|
|
92
109
|
setByYearday(days: readonly number[]): RRule;
|
|
93
110
|
setWeekstart(day: Weekday): RRule;
|
|
94
|
-
setUntil(datetime: DateTime): RRule;
|
|
111
|
+
setUntil(datetime: DateTime | DateTimeLike): RRule;
|
|
95
112
|
toString(): string;
|
|
96
|
-
|
|
113
|
+
toPlain(): RRuleLike;
|
|
97
114
|
}
|
package/dist/browser/rrule.js
CHANGED
|
@@ -36,25 +36,27 @@ export var Weekday;
|
|
|
36
36
|
Weekday[Weekday["Sunday"] = 6] = "Sunday";
|
|
37
37
|
})(Weekday || (Weekday = {}));
|
|
38
38
|
export class RRule {
|
|
39
|
-
constructor(
|
|
40
|
-
if (typeof
|
|
41
|
-
this.frequency =
|
|
42
|
-
this.interval =
|
|
43
|
-
this.until =
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
this.
|
|
47
|
-
this.
|
|
48
|
-
this.
|
|
49
|
-
this.
|
|
50
|
-
this.
|
|
51
|
-
this.
|
|
52
|
-
this.
|
|
53
|
-
this.
|
|
54
|
-
this.
|
|
39
|
+
constructor(frequencyOrOptions) {
|
|
40
|
+
if (typeof frequencyOrOptions === 'object' && frequencyOrOptions !== null) {
|
|
41
|
+
this.frequency = frequencyOrOptions.frequency;
|
|
42
|
+
this.interval = frequencyOrOptions.interval;
|
|
43
|
+
this.until =
|
|
44
|
+
frequencyOrOptions.until &&
|
|
45
|
+
DateTime.fromPlain(frequencyOrOptions.until);
|
|
46
|
+
this.count = frequencyOrOptions.count;
|
|
47
|
+
this.byWeekday = frequencyOrOptions.byWeekday ?? [];
|
|
48
|
+
this.byHour = frequencyOrOptions.byHour ?? [];
|
|
49
|
+
this.byMinute = frequencyOrOptions.byMinute ?? [];
|
|
50
|
+
this.bySecond = frequencyOrOptions.bySecond ?? [];
|
|
51
|
+
this.byMonthday = frequencyOrOptions.byMonthday ?? [];
|
|
52
|
+
this.bySetpos = frequencyOrOptions.bySetpos ?? [];
|
|
53
|
+
this.byMonth = frequencyOrOptions.byMonth ?? [];
|
|
54
|
+
this.byWeekno = frequencyOrOptions.byWeekno ?? [];
|
|
55
|
+
this.byYearday = frequencyOrOptions.byYearday ?? [];
|
|
56
|
+
this.weekstart = frequencyOrOptions.weekstart;
|
|
55
57
|
}
|
|
56
58
|
else {
|
|
57
|
-
this.frequency =
|
|
59
|
+
this.frequency = frequencyOrOptions;
|
|
58
60
|
this.byWeekday = [];
|
|
59
61
|
this.byHour = [];
|
|
60
62
|
this.byMinute = [];
|
|
@@ -73,6 +75,24 @@ export class RRule {
|
|
|
73
75
|
const rust = Rust.parse(str);
|
|
74
76
|
return this.fromRust(rust);
|
|
75
77
|
}
|
|
78
|
+
static fromPlain(rrule) {
|
|
79
|
+
return new this({
|
|
80
|
+
frequency: rrule.frequency,
|
|
81
|
+
interval: rrule.interval,
|
|
82
|
+
until: rrule.until,
|
|
83
|
+
count: rrule.count,
|
|
84
|
+
byWeekday: rrule.byWeekday,
|
|
85
|
+
byHour: rrule.byHour,
|
|
86
|
+
byMinute: rrule.byMinute,
|
|
87
|
+
bySecond: rrule.bySecond,
|
|
88
|
+
byMonthday: rrule.byMonthday,
|
|
89
|
+
bySetpos: rrule.bySetpos,
|
|
90
|
+
byMonth: rrule.byMonth,
|
|
91
|
+
byWeekno: rrule.byWeekno,
|
|
92
|
+
byYearday: rrule.byYearday,
|
|
93
|
+
weekstart: rrule.weekstart,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
76
96
|
/**
|
|
77
97
|
* @internal
|
|
78
98
|
*/
|
|
@@ -96,47 +116,53 @@ export class RRule {
|
|
|
96
116
|
rrule.rust = rust;
|
|
97
117
|
return rrule;
|
|
98
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* @internal
|
|
121
|
+
*/
|
|
122
|
+
static fromPlainOrInstance(rrule) {
|
|
123
|
+
return rrule instanceof RRule ? rrule : this.fromPlain(rrule);
|
|
124
|
+
}
|
|
99
125
|
setFrequency(frequency) {
|
|
100
|
-
return new RRule({ ...this.
|
|
126
|
+
return new RRule({ ...this.toPlain(), frequency });
|
|
101
127
|
}
|
|
102
128
|
setInterval(interval) {
|
|
103
|
-
return new RRule({ ...this.
|
|
129
|
+
return new RRule({ ...this.toPlain(), interval });
|
|
104
130
|
}
|
|
105
131
|
setCount(count) {
|
|
106
|
-
return new RRule({ ...this.
|
|
132
|
+
return new RRule({ ...this.toPlain(), count });
|
|
107
133
|
}
|
|
108
134
|
setByWeekday(weekdays) {
|
|
109
|
-
return new RRule({ ...this.
|
|
135
|
+
return new RRule({ ...this.toPlain(), byWeekday: weekdays });
|
|
110
136
|
}
|
|
111
137
|
setByHour(hours) {
|
|
112
|
-
return new RRule({ ...this.
|
|
138
|
+
return new RRule({ ...this.toPlain(), byHour: hours });
|
|
113
139
|
}
|
|
114
140
|
setByMinute(minutes) {
|
|
115
|
-
return new RRule({ ...this.
|
|
141
|
+
return new RRule({ ...this.toPlain(), byMinute: minutes });
|
|
116
142
|
}
|
|
117
143
|
setBySecond(seconds) {
|
|
118
|
-
return new RRule({ ...this.
|
|
144
|
+
return new RRule({ ...this.toPlain(), bySecond: seconds });
|
|
119
145
|
}
|
|
120
146
|
setByMonthday(days) {
|
|
121
|
-
return new RRule({ ...this.
|
|
147
|
+
return new RRule({ ...this.toPlain(), byMonthday: days });
|
|
122
148
|
}
|
|
123
149
|
setBySetpos(poses) {
|
|
124
|
-
return new RRule({ ...this.
|
|
150
|
+
return new RRule({ ...this.toPlain(), bySetpos: poses });
|
|
125
151
|
}
|
|
126
152
|
setByMonth(months) {
|
|
127
|
-
return new RRule({ ...this.
|
|
153
|
+
return new RRule({ ...this.toPlain(), byMonth: months });
|
|
128
154
|
}
|
|
129
155
|
setByWeekno(weekNumbers) {
|
|
130
|
-
return new RRule({ ...this.
|
|
156
|
+
return new RRule({ ...this.toPlain(), byWeekno: weekNumbers });
|
|
131
157
|
}
|
|
132
158
|
setByYearday(days) {
|
|
133
|
-
return new RRule({ ...this.
|
|
159
|
+
return new RRule({ ...this.toPlain(), byYearday: days });
|
|
134
160
|
}
|
|
135
161
|
setWeekstart(day) {
|
|
136
|
-
return new RRule({ ...this.
|
|
162
|
+
return new RRule({ ...this.toPlain(), weekstart: day });
|
|
137
163
|
}
|
|
138
164
|
setUntil(datetime) {
|
|
139
|
-
return new RRule({ ...this.
|
|
165
|
+
return new RRule({ ...this.toPlain(), until: datetime });
|
|
140
166
|
}
|
|
141
167
|
toString() {
|
|
142
168
|
return this.toRust().toString();
|
|
@@ -148,7 +174,7 @@ export class RRule {
|
|
|
148
174
|
this.rust ??= new Rust(this.frequency, this.interval, this.count, this.weekstart, this.until?.toNumeric(), this.byWeekday, this.byHour, this.byMinute, this.bySecond, this.byMonthday, this.bySetpos, this.byMonth, this.byWeekno, this.byYearday);
|
|
149
175
|
return this.rust;
|
|
150
176
|
}
|
|
151
|
-
|
|
177
|
+
toPlain() {
|
|
152
178
|
return {
|
|
153
179
|
frequency: this.frequency,
|
|
154
180
|
interval: this.interval,
|
|
@@ -163,7 +189,7 @@ export class RRule {
|
|
|
163
189
|
byWeekno: this.byWeekno,
|
|
164
190
|
byYearday: this.byYearday,
|
|
165
191
|
weekstart: this.weekstart,
|
|
166
|
-
until: this.until,
|
|
192
|
+
until: this.until?.toPlain(),
|
|
167
193
|
};
|
|
168
194
|
}
|
|
169
195
|
}
|
package/dist/node/datetime.d.ts
CHANGED
|
@@ -5,9 +5,11 @@ export interface DateTimeLike {
|
|
|
5
5
|
readonly hour: number;
|
|
6
6
|
readonly minute: number;
|
|
7
7
|
readonly second: number;
|
|
8
|
+
readonly utc: boolean;
|
|
8
9
|
}
|
|
9
|
-
export
|
|
10
|
-
|
|
10
|
+
export type DateTimeLikeWithoutUtc = Omit<DateTimeLike, 'utc'>;
|
|
11
|
+
export interface ToPlainOptions {
|
|
12
|
+
stripUtc?: boolean;
|
|
11
13
|
}
|
|
12
14
|
/**
|
|
13
15
|
* Represents a date and time. Either local or UTC.
|
|
@@ -37,7 +39,7 @@ export declare class DateTime implements DateTimeLike {
|
|
|
37
39
|
/**
|
|
38
40
|
* Creates a new DateTime object from the given plain object.
|
|
39
41
|
*/
|
|
40
|
-
static
|
|
42
|
+
static fromPlain(plain: DateTimeLike): DateTime;
|
|
41
43
|
/**
|
|
42
44
|
* Creates a new DateTime object from provided string representation of a date according to RFC 5545.
|
|
43
45
|
*/
|
|
@@ -45,7 +47,13 @@ export declare class DateTime implements DateTimeLike {
|
|
|
45
47
|
/**
|
|
46
48
|
* Converts DateTime into a plain object.
|
|
47
49
|
*/
|
|
48
|
-
|
|
50
|
+
toPlain(options: {
|
|
51
|
+
stripUtc: false;
|
|
52
|
+
} & ToPlainOptions): DateTimeLike;
|
|
53
|
+
toPlain(options: {
|
|
54
|
+
stripUtc: true;
|
|
55
|
+
} & ToPlainOptions): DateTimeLikeWithoutUtc;
|
|
56
|
+
toPlain(): DateTimeLike;
|
|
49
57
|
/**
|
|
50
58
|
* Converts DateTime into ISO 8601 string:
|
|
51
59
|
* - `YYYYMMDDTHHMMSSZ` for UTC
|
package/dist/node/datetime.js
CHANGED
|
@@ -57,8 +57,8 @@ class DateTime {
|
|
|
57
57
|
/**
|
|
58
58
|
* Creates a new DateTime object from the given plain object.
|
|
59
59
|
*/
|
|
60
|
-
static
|
|
61
|
-
return DateTime.create(
|
|
60
|
+
static fromPlain(plain) {
|
|
61
|
+
return DateTime.create(plain.year, plain.month, plain.day, plain.hour, plain.minute, plain.second, plain.utc);
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
64
64
|
* Creates a new DateTime object from provided string representation of a date according to RFC 5545.
|
|
@@ -89,10 +89,11 @@ class DateTime {
|
|
|
89
89
|
static fromNumeric(numeric) {
|
|
90
90
|
return new DateTime(numeric);
|
|
91
91
|
}
|
|
92
|
-
/**
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
92
|
+
/** @internal */
|
|
93
|
+
static fromPlainOrInstance(datetime) {
|
|
94
|
+
return datetime instanceof DateTime ? datetime : this.fromPlain(datetime);
|
|
95
|
+
}
|
|
96
|
+
toPlain(options) {
|
|
96
97
|
return {
|
|
97
98
|
year: this.year,
|
|
98
99
|
month: this.month,
|
|
@@ -100,6 +101,7 @@ class DateTime {
|
|
|
100
101
|
hour: this.hour,
|
|
101
102
|
minute: this.minute,
|
|
102
103
|
second: this.second,
|
|
104
|
+
utc: options?.stripUtc ? undefined : this.utc,
|
|
103
105
|
};
|
|
104
106
|
}
|
|
105
107
|
/**
|
package/dist/node/rrule-set.d.ts
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
import { RRule } from './rrule';
|
|
2
|
-
import { DateTime } from './datetime';
|
|
1
|
+
import { RRule, type RRuleLike } from './rrule';
|
|
2
|
+
import { DateTime, type DateTimeLike } from './datetime';
|
|
3
|
+
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)[];
|
|
10
|
+
}
|
|
3
11
|
export interface RRuleSetLike {
|
|
4
|
-
readonly dtstart:
|
|
12
|
+
readonly dtstart: DateTimeLike;
|
|
5
13
|
readonly tzid?: string;
|
|
6
|
-
readonly rrules: readonly
|
|
7
|
-
readonly exrules: readonly
|
|
8
|
-
readonly exdates: readonly
|
|
9
|
-
readonly rdates: readonly
|
|
14
|
+
readonly rrules: readonly RRuleLike[];
|
|
15
|
+
readonly exrules: readonly RRuleLike[];
|
|
16
|
+
readonly exdates: readonly DateTimeLike[];
|
|
17
|
+
readonly rdates: readonly DateTimeLike[];
|
|
10
18
|
}
|
|
11
19
|
export declare class RRuleSet implements Iterable<DateTime> {
|
|
12
20
|
readonly dtstart: DateTime;
|
|
@@ -15,22 +23,23 @@ export declare class RRuleSet implements Iterable<DateTime> {
|
|
|
15
23
|
readonly exrules: readonly RRule[];
|
|
16
24
|
readonly exdates: readonly DateTime[];
|
|
17
25
|
readonly rdates: readonly DateTime[];
|
|
18
|
-
constructor(dtstart: DateTime, tzid?: string);
|
|
19
|
-
constructor(options:
|
|
26
|
+
constructor(dtstart: DateTime | DateTimeLike, tzid?: string);
|
|
27
|
+
constructor(options: RRuleSetOptions);
|
|
20
28
|
/**
|
|
21
29
|
* Parses a string into an RRuleSet.
|
|
22
30
|
*/
|
|
23
31
|
static parse(str: string): RRuleSet;
|
|
24
|
-
|
|
32
|
+
static fromPlain(plain: RRuleSetLike): RRuleSet;
|
|
33
|
+
setDtstart(dtstart: DateTime | DateTimeLike): RRuleSet;
|
|
25
34
|
setTzid(tzid: string): RRuleSet;
|
|
26
|
-
addRrule(rrule: RRule): RRuleSet;
|
|
27
|
-
setRrules(rrules: readonly RRule[]): RRuleSet;
|
|
28
|
-
addExrule(rrule: RRule): RRuleSet;
|
|
29
|
-
setExrules(rrules: readonly RRule[]): RRuleSet;
|
|
30
|
-
addExdate(datetime: DateTime): RRuleSet;
|
|
31
|
-
setExdates(datetimes: readonly DateTime[]): RRuleSet;
|
|
32
|
-
addRdate(datetime: DateTime): RRuleSet;
|
|
33
|
-
setRdates(datetimes: readonly DateTime[]): 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;
|
|
34
43
|
/**
|
|
35
44
|
* Returns all the occurrences of the rrule.
|
|
36
45
|
*
|
|
@@ -55,6 +64,6 @@ export declare class RRuleSet implements Iterable<DateTime> {
|
|
|
55
64
|
/**
|
|
56
65
|
* Converts the RRuleSet to a plain object.
|
|
57
66
|
*/
|
|
58
|
-
|
|
67
|
+
toPlain(): RRuleSetLike;
|
|
59
68
|
[Symbol.iterator](): Iterator<DateTime, any, any>;
|
|
60
69
|
}
|
package/dist/node/rrule-set.js
CHANGED
|
@@ -5,24 +5,20 @@ const rrule_1 = require("./rrule");
|
|
|
5
5
|
const lib_1 = require("./lib");
|
|
6
6
|
const datetime_1 = require("./datetime");
|
|
7
7
|
class RRuleSet {
|
|
8
|
-
constructor(
|
|
9
|
-
if (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
this.
|
|
18
|
-
this.rrules = setOrDtstart?.rrules ?? [];
|
|
19
|
-
this.exrules = setOrDtstart?.exrules ?? [];
|
|
20
|
-
this.exdates = setOrDtstart?.exdates ?? [];
|
|
21
|
-
this.rdates = setOrDtstart?.rdates ?? [];
|
|
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));
|
|
22
18
|
}
|
|
23
|
-
else if (
|
|
24
|
-
this.dtstart =
|
|
25
|
-
this.tzid = tzid;
|
|
19
|
+
else if (optionsOrDtstart instanceof datetime_1.DateTime) {
|
|
20
|
+
this.dtstart = optionsOrDtstart;
|
|
21
|
+
this.tzid = tzid ?? 'UTC';
|
|
26
22
|
this.rrules = [];
|
|
27
23
|
this.exrules = [];
|
|
28
24
|
this.exdates = [];
|
|
@@ -39,6 +35,9 @@ class RRuleSet {
|
|
|
39
35
|
const rust = lib_1.RRuleSet.parse(str);
|
|
40
36
|
return this.fromRust(rust);
|
|
41
37
|
}
|
|
38
|
+
static fromPlain(plain) {
|
|
39
|
+
return new RRuleSet(plain);
|
|
40
|
+
}
|
|
42
41
|
/**
|
|
43
42
|
* @internal
|
|
44
43
|
*/
|
|
@@ -56,61 +55,61 @@ class RRuleSet {
|
|
|
56
55
|
}
|
|
57
56
|
setDtstart(dtstart) {
|
|
58
57
|
return new RRuleSet({
|
|
59
|
-
...this.
|
|
58
|
+
...this.toPlain(),
|
|
60
59
|
dtstart: dtstart,
|
|
61
60
|
});
|
|
62
61
|
}
|
|
63
62
|
setTzid(tzid) {
|
|
64
63
|
return new RRuleSet({
|
|
65
|
-
...this.
|
|
64
|
+
...this.toPlain(),
|
|
66
65
|
tzid: tzid,
|
|
67
66
|
});
|
|
68
67
|
}
|
|
69
68
|
addRrule(rrule) {
|
|
70
69
|
return new RRuleSet({
|
|
71
|
-
...this.
|
|
70
|
+
...this.toPlain(),
|
|
72
71
|
rrules: [...this.rrules, rrule],
|
|
73
72
|
});
|
|
74
73
|
}
|
|
75
74
|
setRrules(rrules) {
|
|
76
75
|
return new RRuleSet({
|
|
77
|
-
...this.
|
|
76
|
+
...this.toPlain(),
|
|
78
77
|
rrules: rrules,
|
|
79
78
|
});
|
|
80
79
|
}
|
|
81
80
|
addExrule(rrule) {
|
|
82
81
|
return new RRuleSet({
|
|
83
|
-
...this.
|
|
82
|
+
...this.toPlain(),
|
|
84
83
|
exrules: [...this.exrules, rrule],
|
|
85
84
|
});
|
|
86
85
|
}
|
|
87
86
|
setExrules(rrules) {
|
|
88
87
|
return new RRuleSet({
|
|
89
|
-
...this.
|
|
88
|
+
...this.toPlain(),
|
|
90
89
|
exrules: rrules,
|
|
91
90
|
});
|
|
92
91
|
}
|
|
93
92
|
addExdate(datetime) {
|
|
94
93
|
return new RRuleSet({
|
|
95
|
-
...this.
|
|
94
|
+
...this.toPlain(),
|
|
96
95
|
exdates: [...this.exdates, datetime],
|
|
97
96
|
});
|
|
98
97
|
}
|
|
99
98
|
setExdates(datetimes) {
|
|
100
99
|
return new RRuleSet({
|
|
101
|
-
...this.
|
|
100
|
+
...this.toPlain(),
|
|
102
101
|
exdates: datetimes,
|
|
103
102
|
});
|
|
104
103
|
}
|
|
105
104
|
addRdate(datetime) {
|
|
106
105
|
return new RRuleSet({
|
|
107
|
-
...this.
|
|
106
|
+
...this.toPlain(),
|
|
108
107
|
rdates: [...this.rdates, datetime],
|
|
109
108
|
});
|
|
110
109
|
}
|
|
111
110
|
setRdates(datetimes) {
|
|
112
111
|
return new RRuleSet({
|
|
113
|
-
...this.
|
|
112
|
+
...this.toPlain(),
|
|
114
113
|
rdates: datetimes,
|
|
115
114
|
});
|
|
116
115
|
}
|
|
@@ -157,14 +156,14 @@ class RRuleSet {
|
|
|
157
156
|
/**
|
|
158
157
|
* Converts the RRuleSet to a plain object.
|
|
159
158
|
*/
|
|
160
|
-
|
|
159
|
+
toPlain() {
|
|
161
160
|
return {
|
|
162
|
-
dtstart: this.dtstart,
|
|
161
|
+
dtstart: this.dtstart.toPlain(),
|
|
163
162
|
tzid: this.tzid,
|
|
164
|
-
rrules: this.rrules,
|
|
165
|
-
exrules: this.exrules,
|
|
166
|
-
exdates: this.exdates,
|
|
167
|
-
rdates: this.rdates,
|
|
163
|
+
rrules: this.rrules.map((rrule) => rrule.toPlain()),
|
|
164
|
+
exrules: this.exrules.map((rrule) => rrule.toPlain()),
|
|
165
|
+
exdates: this.exdates.map((rrule) => rrule.toPlain()),
|
|
166
|
+
rdates: this.rdates.map((rrule) => rrule.toPlain()),
|
|
168
167
|
};
|
|
169
168
|
}
|
|
170
169
|
[Symbol.iterator]() {
|
package/dist/node/rrule.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DateTime } from './datetime';
|
|
1
|
+
import { DateTime, type DateTimeLike } from './datetime';
|
|
2
2
|
export interface NWeekday {
|
|
3
3
|
/**
|
|
4
4
|
* If set, this represents the nth occurrence of the weekday.
|
|
@@ -41,11 +41,27 @@ export declare enum Weekday {
|
|
|
41
41
|
Saturday = 5,
|
|
42
42
|
Sunday = 6
|
|
43
43
|
}
|
|
44
|
+
export interface RRuleOptions {
|
|
45
|
+
readonly frequency: Frequency;
|
|
46
|
+
readonly interval?: number;
|
|
47
|
+
readonly count?: number;
|
|
48
|
+
readonly until?: DateTime | DateTimeLike;
|
|
49
|
+
readonly byWeekday?: readonly (NWeekday | Weekday)[];
|
|
50
|
+
readonly byHour?: readonly number[];
|
|
51
|
+
readonly byMinute?: readonly number[];
|
|
52
|
+
readonly bySecond?: readonly number[];
|
|
53
|
+
readonly byMonthday?: readonly number[];
|
|
54
|
+
readonly bySetpos?: readonly number[];
|
|
55
|
+
readonly byMonth?: readonly Month[];
|
|
56
|
+
readonly byWeekno?: readonly number[];
|
|
57
|
+
readonly byYearday?: readonly number[];
|
|
58
|
+
readonly weekstart?: Weekday;
|
|
59
|
+
}
|
|
44
60
|
export interface RRuleLike {
|
|
45
61
|
readonly frequency: Frequency;
|
|
46
62
|
readonly interval?: number;
|
|
47
63
|
readonly count?: number;
|
|
48
|
-
readonly until?:
|
|
64
|
+
readonly until?: DateTimeLike;
|
|
49
65
|
readonly byWeekday: readonly (NWeekday | Weekday)[];
|
|
50
66
|
readonly byHour: readonly number[];
|
|
51
67
|
readonly byMinute: readonly number[];
|
|
@@ -73,11 +89,12 @@ export declare class RRule {
|
|
|
73
89
|
readonly byYearday: readonly number[];
|
|
74
90
|
readonly weekstart?: Weekday;
|
|
75
91
|
constructor(frequency: Frequency);
|
|
76
|
-
constructor(
|
|
92
|
+
constructor(options: RRuleOptions);
|
|
77
93
|
/**
|
|
78
94
|
* Parses a string into an RRule.
|
|
79
95
|
*/
|
|
80
96
|
static parse(str: string): RRule;
|
|
97
|
+
static fromPlain(rrule: RRuleLike): RRule;
|
|
81
98
|
setFrequency(frequency: Frequency): RRule;
|
|
82
99
|
setInterval(interval: number): RRule;
|
|
83
100
|
setCount(count: number): RRule;
|
|
@@ -91,7 +108,7 @@ export declare class RRule {
|
|
|
91
108
|
setByWeekno(weekNumbers: readonly number[]): RRule;
|
|
92
109
|
setByYearday(days: readonly number[]): RRule;
|
|
93
110
|
setWeekstart(day: Weekday): RRule;
|
|
94
|
-
setUntil(datetime: DateTime): RRule;
|
|
111
|
+
setUntil(datetime: DateTime | DateTimeLike): RRule;
|
|
95
112
|
toString(): string;
|
|
96
|
-
|
|
113
|
+
toPlain(): RRuleLike;
|
|
97
114
|
}
|
package/dist/node/rrule.js
CHANGED
|
@@ -39,25 +39,27 @@ var Weekday;
|
|
|
39
39
|
Weekday[Weekday["Sunday"] = 6] = "Sunday";
|
|
40
40
|
})(Weekday || (exports.Weekday = Weekday = {}));
|
|
41
41
|
class RRule {
|
|
42
|
-
constructor(
|
|
43
|
-
if (typeof
|
|
44
|
-
this.frequency =
|
|
45
|
-
this.interval =
|
|
46
|
-
this.until =
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
this.
|
|
50
|
-
this.
|
|
51
|
-
this.
|
|
52
|
-
this.
|
|
53
|
-
this.
|
|
54
|
-
this.
|
|
55
|
-
this.
|
|
56
|
-
this.
|
|
57
|
-
this.
|
|
42
|
+
constructor(frequencyOrOptions) {
|
|
43
|
+
if (typeof frequencyOrOptions === 'object' && frequencyOrOptions !== null) {
|
|
44
|
+
this.frequency = frequencyOrOptions.frequency;
|
|
45
|
+
this.interval = frequencyOrOptions.interval;
|
|
46
|
+
this.until =
|
|
47
|
+
frequencyOrOptions.until &&
|
|
48
|
+
datetime_1.DateTime.fromPlain(frequencyOrOptions.until);
|
|
49
|
+
this.count = frequencyOrOptions.count;
|
|
50
|
+
this.byWeekday = frequencyOrOptions.byWeekday ?? [];
|
|
51
|
+
this.byHour = frequencyOrOptions.byHour ?? [];
|
|
52
|
+
this.byMinute = frequencyOrOptions.byMinute ?? [];
|
|
53
|
+
this.bySecond = frequencyOrOptions.bySecond ?? [];
|
|
54
|
+
this.byMonthday = frequencyOrOptions.byMonthday ?? [];
|
|
55
|
+
this.bySetpos = frequencyOrOptions.bySetpos ?? [];
|
|
56
|
+
this.byMonth = frequencyOrOptions.byMonth ?? [];
|
|
57
|
+
this.byWeekno = frequencyOrOptions.byWeekno ?? [];
|
|
58
|
+
this.byYearday = frequencyOrOptions.byYearday ?? [];
|
|
59
|
+
this.weekstart = frequencyOrOptions.weekstart;
|
|
58
60
|
}
|
|
59
61
|
else {
|
|
60
|
-
this.frequency =
|
|
62
|
+
this.frequency = frequencyOrOptions;
|
|
61
63
|
this.byWeekday = [];
|
|
62
64
|
this.byHour = [];
|
|
63
65
|
this.byMinute = [];
|
|
@@ -76,6 +78,24 @@ class RRule {
|
|
|
76
78
|
const rust = lib_1.RRule.parse(str);
|
|
77
79
|
return this.fromRust(rust);
|
|
78
80
|
}
|
|
81
|
+
static fromPlain(rrule) {
|
|
82
|
+
return new this({
|
|
83
|
+
frequency: rrule.frequency,
|
|
84
|
+
interval: rrule.interval,
|
|
85
|
+
until: rrule.until,
|
|
86
|
+
count: rrule.count,
|
|
87
|
+
byWeekday: rrule.byWeekday,
|
|
88
|
+
byHour: rrule.byHour,
|
|
89
|
+
byMinute: rrule.byMinute,
|
|
90
|
+
bySecond: rrule.bySecond,
|
|
91
|
+
byMonthday: rrule.byMonthday,
|
|
92
|
+
bySetpos: rrule.bySetpos,
|
|
93
|
+
byMonth: rrule.byMonth,
|
|
94
|
+
byWeekno: rrule.byWeekno,
|
|
95
|
+
byYearday: rrule.byYearday,
|
|
96
|
+
weekstart: rrule.weekstart,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
79
99
|
/**
|
|
80
100
|
* @internal
|
|
81
101
|
*/
|
|
@@ -99,47 +119,53 @@ class RRule {
|
|
|
99
119
|
rrule.rust = rust;
|
|
100
120
|
return rrule;
|
|
101
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* @internal
|
|
124
|
+
*/
|
|
125
|
+
static fromPlainOrInstance(rrule) {
|
|
126
|
+
return rrule instanceof RRule ? rrule : this.fromPlain(rrule);
|
|
127
|
+
}
|
|
102
128
|
setFrequency(frequency) {
|
|
103
|
-
return new RRule({ ...this.
|
|
129
|
+
return new RRule({ ...this.toPlain(), frequency });
|
|
104
130
|
}
|
|
105
131
|
setInterval(interval) {
|
|
106
|
-
return new RRule({ ...this.
|
|
132
|
+
return new RRule({ ...this.toPlain(), interval });
|
|
107
133
|
}
|
|
108
134
|
setCount(count) {
|
|
109
|
-
return new RRule({ ...this.
|
|
135
|
+
return new RRule({ ...this.toPlain(), count });
|
|
110
136
|
}
|
|
111
137
|
setByWeekday(weekdays) {
|
|
112
|
-
return new RRule({ ...this.
|
|
138
|
+
return new RRule({ ...this.toPlain(), byWeekday: weekdays });
|
|
113
139
|
}
|
|
114
140
|
setByHour(hours) {
|
|
115
|
-
return new RRule({ ...this.
|
|
141
|
+
return new RRule({ ...this.toPlain(), byHour: hours });
|
|
116
142
|
}
|
|
117
143
|
setByMinute(minutes) {
|
|
118
|
-
return new RRule({ ...this.
|
|
144
|
+
return new RRule({ ...this.toPlain(), byMinute: minutes });
|
|
119
145
|
}
|
|
120
146
|
setBySecond(seconds) {
|
|
121
|
-
return new RRule({ ...this.
|
|
147
|
+
return new RRule({ ...this.toPlain(), bySecond: seconds });
|
|
122
148
|
}
|
|
123
149
|
setByMonthday(days) {
|
|
124
|
-
return new RRule({ ...this.
|
|
150
|
+
return new RRule({ ...this.toPlain(), byMonthday: days });
|
|
125
151
|
}
|
|
126
152
|
setBySetpos(poses) {
|
|
127
|
-
return new RRule({ ...this.
|
|
153
|
+
return new RRule({ ...this.toPlain(), bySetpos: poses });
|
|
128
154
|
}
|
|
129
155
|
setByMonth(months) {
|
|
130
|
-
return new RRule({ ...this.
|
|
156
|
+
return new RRule({ ...this.toPlain(), byMonth: months });
|
|
131
157
|
}
|
|
132
158
|
setByWeekno(weekNumbers) {
|
|
133
|
-
return new RRule({ ...this.
|
|
159
|
+
return new RRule({ ...this.toPlain(), byWeekno: weekNumbers });
|
|
134
160
|
}
|
|
135
161
|
setByYearday(days) {
|
|
136
|
-
return new RRule({ ...this.
|
|
162
|
+
return new RRule({ ...this.toPlain(), byYearday: days });
|
|
137
163
|
}
|
|
138
164
|
setWeekstart(day) {
|
|
139
|
-
return new RRule({ ...this.
|
|
165
|
+
return new RRule({ ...this.toPlain(), weekstart: day });
|
|
140
166
|
}
|
|
141
167
|
setUntil(datetime) {
|
|
142
|
-
return new RRule({ ...this.
|
|
168
|
+
return new RRule({ ...this.toPlain(), until: datetime });
|
|
143
169
|
}
|
|
144
170
|
toString() {
|
|
145
171
|
return this.toRust().toString();
|
|
@@ -151,7 +177,7 @@ class RRule {
|
|
|
151
177
|
this.rust ??= new lib_1.RRule(this.frequency, this.interval, this.count, this.weekstart, this.until?.toNumeric(), this.byWeekday, this.byHour, this.byMinute, this.bySecond, this.byMonthday, this.bySetpos, this.byMonth, this.byWeekno, this.byYearday);
|
|
152
178
|
return this.rust;
|
|
153
179
|
}
|
|
154
|
-
|
|
180
|
+
toPlain() {
|
|
155
181
|
return {
|
|
156
182
|
frequency: this.frequency,
|
|
157
183
|
interval: this.interval,
|
|
@@ -166,7 +192,7 @@ class RRule {
|
|
|
166
192
|
byWeekno: this.byWeekno,
|
|
167
193
|
byYearday: this.byYearday,
|
|
168
194
|
weekstart: this.weekstart,
|
|
169
|
-
until: this.until,
|
|
195
|
+
until: this.until?.toPlain(),
|
|
170
196
|
};
|
|
171
197
|
}
|
|
172
198
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rrule-rust",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.4",
|
|
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.
|
|
100
|
-
"@rrule-rust/lib-darwin-x64": "3.0.0-alpha.
|
|
101
|
-
"@rrule-rust/lib-linux-x64-gnu": "3.0.0-alpha.
|
|
102
|
-
"@rrule-rust/lib-linux-x64-musl": "3.0.0-alpha.
|
|
103
|
-
"@rrule-rust/lib-linux-arm64-gnu": "3.0.0-alpha.
|
|
104
|
-
"@rrule-rust/lib-win32-ia32-msvc": "3.0.0-alpha.
|
|
105
|
-
"@rrule-rust/lib-linux-arm-gnueabihf": "3.0.0-alpha.
|
|
106
|
-
"@rrule-rust/lib-darwin-arm64": "3.0.0-alpha.
|
|
107
|
-
"@rrule-rust/lib-android-arm64": "3.0.0-alpha.
|
|
108
|
-
"@rrule-rust/lib-freebsd-x64": "3.0.0-alpha.
|
|
109
|
-
"@rrule-rust/lib-linux-arm64-musl": "3.0.0-alpha.
|
|
110
|
-
"@rrule-rust/lib-win32-arm64-msvc": "3.0.0-alpha.
|
|
111
|
-
"@rrule-rust/lib-android-arm-eabi": "3.0.0-alpha.
|
|
112
|
-
"@rrule-rust/lib-wasm32-wasi": "3.0.0-alpha.
|
|
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"
|
|
113
113
|
}
|
|
114
114
|
}
|