rrule-rust 3.0.0-alpha.6 → 3.0.0-alpha.8
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 +32 -18
- package/dist/browser/datetime.js +115 -59
- package/dist/browser/dtstart.d.ts +14 -13
- package/dist/browser/dtstart.js +3 -9
- package/dist/browser/exdate.d.ts +20 -0
- package/dist/browser/exdate.js +47 -0
- package/dist/browser/index.d.ts +2 -0
- package/dist/browser/index.js +2 -0
- package/dist/browser/rdate.d.ts +20 -0
- package/dist/browser/rdate.js +47 -0
- package/dist/browser/rrule-set.d.ts +40 -37
- package/dist/browser/rrule-set.js +13 -12
- package/dist/browser/rrule.d.ts +26 -25
- package/dist/browser/rrule.js +4 -6
- package/dist/node/datetime.d.ts +32 -18
- package/dist/node/datetime.js +115 -59
- package/dist/node/dtstart.d.ts +14 -13
- package/dist/node/dtstart.js +2 -8
- package/dist/node/exdate.d.ts +20 -0
- package/dist/node/exdate.js +51 -0
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.js +2 -0
- package/dist/node/lib/index.js +2 -0
- package/dist/node/lib/rrule-rust.wasi.cjs +2 -0
- package/dist/node/rdate.d.ts +20 -0
- package/dist/node/rdate.js +51 -0
- package/dist/node/rrule-set.d.ts +40 -37
- package/dist/node/rrule-set.js +12 -11
- package/dist/node/rrule.d.ts +26 -25
- package/dist/node/rrule.js +3 -5
- package/package.json +15 -15
|
@@ -1,7 +1,9 @@
|
|
|
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
4
|
import { DtStart } from './dtstart';
|
|
5
|
+
import { ExDate } from './exdate';
|
|
6
|
+
import { RDate } from './rdate';
|
|
5
7
|
export class RRuleSet {
|
|
6
8
|
constructor(optionsOrDtstart) {
|
|
7
9
|
if ('dtstart' in optionsOrDtstart) {
|
|
@@ -23,16 +25,15 @@ export class RRuleSet {
|
|
|
23
25
|
* Parses a string into an RRuleSet.
|
|
24
26
|
*/
|
|
25
27
|
static parse(str) {
|
|
26
|
-
|
|
27
|
-
return this.fromRust(rust);
|
|
28
|
+
return this.fromRust(Rust.parse(str));
|
|
28
29
|
}
|
|
29
30
|
static fromPlain(plain) {
|
|
30
31
|
return new RRuleSet({
|
|
31
32
|
dtstart: DtStart.fromPlain(plain.dtstart),
|
|
32
33
|
rrules: plain.rrules.map((rrule) => RRule.fromPlain(rrule)),
|
|
33
34
|
exrules: plain.exrules.map((rrule) => RRule.fromPlain(rrule)),
|
|
34
|
-
exdates: plain.exdates.map((datetime) =>
|
|
35
|
-
rdates: plain.rdates.map((datetime) =>
|
|
35
|
+
exdates: plain.exdates.map((datetime) => ExDate.fromPlain(datetime)),
|
|
36
|
+
rdates: plain.rdates.map((datetime) => RDate.fromPlain(datetime)),
|
|
36
37
|
});
|
|
37
38
|
}
|
|
38
39
|
/**
|
|
@@ -46,8 +47,8 @@ export class RRuleSet {
|
|
|
46
47
|
}),
|
|
47
48
|
rrules: rust.rrules.map((rrule) => RRule.fromRust(rrule)),
|
|
48
49
|
exrules: rust.exrules.map((rrule) => RRule.fromRust(rrule)),
|
|
49
|
-
exdates: rust.exdates.map((
|
|
50
|
-
rdates: rust.rdates.map((
|
|
50
|
+
exdates: rust.exdates.map((exdate) => ExDate.fromRust(exdate)),
|
|
51
|
+
rdates: rust.rdates.map((rdate) => RDate.fromRust(rdate)),
|
|
51
52
|
});
|
|
52
53
|
set.rust = rust;
|
|
53
54
|
return set;
|
|
@@ -82,16 +83,16 @@ export class RRuleSet {
|
|
|
82
83
|
exrules: rrules,
|
|
83
84
|
});
|
|
84
85
|
}
|
|
85
|
-
addExdate(
|
|
86
|
+
addExdate(exdate) {
|
|
86
87
|
return new RRuleSet({
|
|
87
88
|
...this.toOptions(),
|
|
88
|
-
exdates: [...this.exdates,
|
|
89
|
+
exdates: [...this.exdates, exdate],
|
|
89
90
|
});
|
|
90
91
|
}
|
|
91
|
-
setExdates(
|
|
92
|
+
setExdates(exdates) {
|
|
92
93
|
return new RRuleSet({
|
|
93
94
|
...this.toOptions(),
|
|
94
|
-
exdates:
|
|
95
|
+
exdates: exdates,
|
|
95
96
|
});
|
|
96
97
|
}
|
|
97
98
|
addRdate(datetime) {
|
|
@@ -140,7 +141,7 @@ export class RRuleSet {
|
|
|
140
141
|
* @internal
|
|
141
142
|
*/
|
|
142
143
|
toRust() {
|
|
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((
|
|
144
|
+
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((exdate) => exdate.toRust()), this.rdates.map((rdate) => rdate.toRust()));
|
|
144
145
|
return this.rust;
|
|
145
146
|
}
|
|
146
147
|
toString() {
|
package/dist/browser/rrule.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DateTime, type DateTimeLike } from './datetime';
|
|
1
|
+
import { type Time, DateTime, type DateTimeLike, type DateLike } from './datetime';
|
|
2
2
|
export interface NWeekday {
|
|
3
3
|
/**
|
|
4
4
|
* If set, this represents the nth occurrence of the weekday.
|
|
@@ -41,11 +41,11 @@ export declare enum Weekday {
|
|
|
41
41
|
Saturday = 5,
|
|
42
42
|
Sunday = 6
|
|
43
43
|
}
|
|
44
|
-
export interface RRuleOptions {
|
|
44
|
+
export interface RRuleOptions<DT extends DateTime<Time> | DateTime<undefined>> {
|
|
45
45
|
readonly frequency: Frequency;
|
|
46
46
|
readonly interval?: number;
|
|
47
47
|
readonly count?: number;
|
|
48
|
-
readonly until?:
|
|
48
|
+
readonly until?: DT;
|
|
49
49
|
readonly byWeekday?: readonly (NWeekday | Weekday)[];
|
|
50
50
|
readonly byHour?: readonly number[];
|
|
51
51
|
readonly byMinute?: readonly number[];
|
|
@@ -57,11 +57,11 @@ export interface RRuleOptions {
|
|
|
57
57
|
readonly byYearday?: readonly number[];
|
|
58
58
|
readonly weekstart?: Weekday;
|
|
59
59
|
}
|
|
60
|
-
export interface RRuleLike {
|
|
60
|
+
export interface RRuleLike<DT extends DateTimeLike | DateLike> {
|
|
61
61
|
readonly frequency: Frequency;
|
|
62
62
|
readonly interval?: number;
|
|
63
63
|
readonly count?: number;
|
|
64
|
-
readonly until?:
|
|
64
|
+
readonly until?: DT;
|
|
65
65
|
readonly byWeekday: readonly (NWeekday | Weekday)[];
|
|
66
66
|
readonly byHour: readonly number[];
|
|
67
67
|
readonly byMinute: readonly number[];
|
|
@@ -73,10 +73,10 @@ export interface RRuleLike {
|
|
|
73
73
|
readonly byYearday: readonly number[];
|
|
74
74
|
readonly weekstart?: Weekday;
|
|
75
75
|
}
|
|
76
|
-
export declare class RRule {
|
|
76
|
+
export declare class RRule<DT extends DateTime<Time> | DateTime<undefined> = DateTime<Time>> {
|
|
77
77
|
readonly frequency: Frequency;
|
|
78
78
|
readonly interval?: number;
|
|
79
|
-
readonly until?:
|
|
79
|
+
readonly until?: DT;
|
|
80
80
|
readonly count?: number;
|
|
81
81
|
readonly byWeekday: readonly (NWeekday | Weekday)[];
|
|
82
82
|
readonly byHour: readonly number[];
|
|
@@ -89,27 +89,28 @@ export declare class RRule {
|
|
|
89
89
|
readonly byYearday: readonly number[];
|
|
90
90
|
readonly weekstart?: Weekday;
|
|
91
91
|
constructor(frequency: Frequency);
|
|
92
|
-
constructor(options: RRuleOptions);
|
|
92
|
+
constructor(options: RRuleOptions<DT>);
|
|
93
93
|
/**
|
|
94
94
|
* Parses a string into an RRule.
|
|
95
95
|
*/
|
|
96
|
-
static parse(str: string): RRule
|
|
97
|
-
static fromPlain(rrule: RRuleLike): RRule
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
96
|
+
static parse<DT extends DateTime<Time> | DateTime<undefined>>(str: string): RRule<DT>;
|
|
97
|
+
static fromPlain(rrule: RRuleLike<DateTimeLike>): RRule<DateTime<Time>>;
|
|
98
|
+
static fromPlain(rrule: RRuleLike<DateLike>): RRule<DateTime<undefined>>;
|
|
99
|
+
setFrequency(frequency: Frequency): RRule<DT>;
|
|
100
|
+
setInterval(interval: number): RRule<DT>;
|
|
101
|
+
setCount(count: number): RRule<DT>;
|
|
102
|
+
setByWeekday(weekdays: readonly (NWeekday | Weekday)[]): RRule<DT>;
|
|
103
|
+
setByHour(hours: readonly number[]): RRule<DT>;
|
|
104
|
+
setByMinute(minutes: readonly number[]): RRule<DT>;
|
|
105
|
+
setBySecond(seconds: readonly number[]): RRule<DT>;
|
|
106
|
+
setByMonthday(days: readonly number[]): RRule<DT>;
|
|
107
|
+
setBySetpos(poses: readonly number[]): RRule<DT>;
|
|
108
|
+
setByMonth(months: readonly Month[]): RRule<DT>;
|
|
109
|
+
setByWeekno(weekNumbers: readonly number[]): RRule<DT>;
|
|
110
|
+
setByYearday(days: readonly number[]): RRule<DT>;
|
|
111
|
+
setWeekstart(day: Weekday): RRule<DT>;
|
|
112
|
+
setUntil(until: DT): RRule<DT>;
|
|
112
113
|
toString(): string;
|
|
113
|
-
toPlain(): RRuleLike
|
|
114
|
+
toPlain(): RRuleLike<DT extends DateTime<Time> ? DateTimeLike : DateLike>;
|
|
114
115
|
private toOptions;
|
|
115
116
|
}
|
package/dist/browser/rrule.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DateTime } from './datetime';
|
|
1
|
+
import { DateTime, } from './datetime';
|
|
2
2
|
import { RRule as Rust } from './lib';
|
|
3
3
|
export var Frequency;
|
|
4
4
|
(function (Frequency) {
|
|
@@ -40,9 +40,7 @@ export class RRule {
|
|
|
40
40
|
if (typeof frequencyOrOptions === 'object' && frequencyOrOptions !== null) {
|
|
41
41
|
this.frequency = frequencyOrOptions.frequency;
|
|
42
42
|
this.interval = frequencyOrOptions.interval;
|
|
43
|
-
this.until =
|
|
44
|
-
frequencyOrOptions.until &&
|
|
45
|
-
DateTime.fromPlain(frequencyOrOptions.until);
|
|
43
|
+
this.until = frequencyOrOptions.until;
|
|
46
44
|
this.count = frequencyOrOptions.count;
|
|
47
45
|
this.byWeekday = frequencyOrOptions.byWeekday ?? [];
|
|
48
46
|
this.byHour = frequencyOrOptions.byHour ?? [];
|
|
@@ -155,8 +153,8 @@ export class RRule {
|
|
|
155
153
|
setWeekstart(day) {
|
|
156
154
|
return new RRule({ ...this.toOptions(), weekstart: day });
|
|
157
155
|
}
|
|
158
|
-
setUntil(
|
|
159
|
-
return new RRule({ ...this.toOptions(), until
|
|
156
|
+
setUntil(until) {
|
|
157
|
+
return new RRule({ ...this.toOptions(), until });
|
|
160
158
|
}
|
|
161
159
|
toString() {
|
|
162
160
|
return this.toRust().toString();
|
package/dist/node/datetime.d.ts
CHANGED
|
@@ -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
|
|
11
|
-
|
|
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
|
|
18
|
-
private readonly
|
|
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
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
|
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
|
-
}
|
|
53
|
-
toPlain(options
|
|
65
|
+
}): DTL;
|
|
66
|
+
toPlain<DTL extends Omit<DateTimeLike, 'utc'>>(options?: ToPlainDateTimeOptions & {
|
|
54
67
|
stripUtc: true;
|
|
55
|
-
}
|
|
56
|
-
toPlain():
|
|
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
|
*/
|
package/dist/node/datetime.js
CHANGED
|
@@ -6,41 +6,64 @@ exports.DateTime = void 0;
|
|
|
6
6
|
*/
|
|
7
7
|
class DateTime {
|
|
8
8
|
constructor(numeric) {
|
|
9
|
-
this.
|
|
9
|
+
this.state = {
|
|
10
|
+
numeric,
|
|
11
|
+
};
|
|
10
12
|
}
|
|
11
13
|
get year() {
|
|
12
|
-
return Math.floor(this.numeric / 100000000000);
|
|
14
|
+
return (this.state.year ??= Math.floor(this.state.numeric / 100000000000));
|
|
13
15
|
}
|
|
14
16
|
get month() {
|
|
15
|
-
return Math.floor((this.numeric / 1000000000) % 100);
|
|
17
|
+
return (this.state.month ??= Math.floor((this.state.numeric / 1000000000) % 100));
|
|
16
18
|
}
|
|
17
19
|
get day() {
|
|
18
|
-
return Math.floor((this.numeric / 10000000) % 100);
|
|
19
|
-
}
|
|
20
|
-
get hour() {
|
|
21
|
-
return Math.floor((this.numeric / 100000) % 100);
|
|
22
|
-
}
|
|
23
|
-
get minute() {
|
|
24
|
-
return Math.floor((this.numeric / 1000) % 100);
|
|
20
|
+
return (this.state.day ??= Math.floor((this.state.numeric / 10000000) % 100));
|
|
25
21
|
}
|
|
26
|
-
get
|
|
27
|
-
return
|
|
22
|
+
get time() {
|
|
23
|
+
// return cached time if available
|
|
24
|
+
if ('time' in this.state) {
|
|
25
|
+
return this.state.time;
|
|
26
|
+
}
|
|
27
|
+
const type = this.state.numeric % 10; // 0 – non utc, 1 – utc, 2 – date only
|
|
28
|
+
if (type == 2) {
|
|
29
|
+
// if it's date only, return undefined and cache it in state
|
|
30
|
+
return (this.state.time ??= undefined);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
// otherwise compute it from numeric representation and cache it in state
|
|
34
|
+
return (this.state.time ??= {
|
|
35
|
+
hour: Math.floor((this.state.numeric / 100000) % 100),
|
|
36
|
+
minute: Math.floor((this.state.numeric / 1000) % 100),
|
|
37
|
+
second: Math.floor((this.state.numeric / 10) % 100),
|
|
38
|
+
utc: this.state.numeric % 10 == 1,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
28
41
|
}
|
|
29
|
-
|
|
30
|
-
|
|
42
|
+
static create(year, month, day, hour, minute, second, utc) {
|
|
43
|
+
let numeric = year * 100000000000 + month * 1000000000 + day * 10000000;
|
|
44
|
+
if (hour !== undefined &&
|
|
45
|
+
minute !== undefined &&
|
|
46
|
+
second !== undefined &&
|
|
47
|
+
utc !== undefined) {
|
|
48
|
+
numeric += hour * 100000;
|
|
49
|
+
numeric += minute * 1000;
|
|
50
|
+
numeric += second * 10;
|
|
51
|
+
numeric += utc ? 1 : 0;
|
|
52
|
+
return new DateTime(numeric);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
numeric += 100000;
|
|
56
|
+
numeric += 1000;
|
|
57
|
+
numeric += 10;
|
|
58
|
+
numeric += 2;
|
|
59
|
+
return new DateTime(numeric);
|
|
60
|
+
}
|
|
31
61
|
}
|
|
32
62
|
/**
|
|
33
63
|
* Creates a new DateTime object from the given date and time components.
|
|
34
64
|
*/
|
|
35
|
-
static
|
|
36
|
-
|
|
37
|
-
month * 1000000000 +
|
|
38
|
-
day * 10000000 +
|
|
39
|
-
hour * 100000 +
|
|
40
|
-
minute * 1000 +
|
|
41
|
-
second * 10 +
|
|
42
|
-
(utc ? 1 : 0);
|
|
43
|
-
return new DateTime(numeric);
|
|
65
|
+
static date(year, month, day) {
|
|
66
|
+
return this.create(year, month, day);
|
|
44
67
|
}
|
|
45
68
|
/**
|
|
46
69
|
* This method is shorthand for `DateTime.create` with `utc` set to `false`.
|
|
@@ -54,69 +77,102 @@ class DateTime {
|
|
|
54
77
|
static utc(year, month, day, hour, minute, second) {
|
|
55
78
|
return DateTime.create(year, month, day, hour, minute, second, true);
|
|
56
79
|
}
|
|
57
|
-
/**
|
|
58
|
-
* Creates a new DateTime object from the given plain object.
|
|
59
|
-
*/
|
|
60
80
|
static fromPlain(plain) {
|
|
61
|
-
|
|
81
|
+
if ('hour' in plain) {
|
|
82
|
+
return DateTime.create(plain.year, plain.month, plain.day, plain.hour, plain.minute, plain.second, plain.utc);
|
|
83
|
+
}
|
|
84
|
+
return DateTime.create(plain.year, plain.month, plain.day);
|
|
62
85
|
}
|
|
63
86
|
/**
|
|
64
87
|
* Creates a new DateTime object from provided string representation of a date according to RFC 5545.
|
|
65
88
|
*/
|
|
89
|
+
// TODO: add template expression
|
|
66
90
|
static fromString(str) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
throw typeError;
|
|
91
|
+
if (!(str.length === 8 || (str.length <= 16 && str.length >= 15))) {
|
|
92
|
+
throw new TypeError('Invalid date time string');
|
|
70
93
|
}
|
|
71
94
|
const year = parseInt(str.slice(0, 4));
|
|
72
95
|
const month = parseInt(str.slice(4, 6));
|
|
73
96
|
const day = parseInt(str.slice(6, 8));
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (isNaN(year) ||
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
97
|
+
let hour = undefined;
|
|
98
|
+
let minute = undefined;
|
|
99
|
+
let second = undefined;
|
|
100
|
+
let utc = undefined;
|
|
101
|
+
if (isNaN(year) || isNaN(month) || isNaN(day)) {
|
|
102
|
+
throw new TypeError('Invalid date');
|
|
103
|
+
}
|
|
104
|
+
if (str.length > 8) {
|
|
105
|
+
hour = parseInt(str.slice(9, 11));
|
|
106
|
+
minute = parseInt(str.slice(11, 13));
|
|
107
|
+
second = parseInt(str.slice(13, 15));
|
|
108
|
+
utc = str.endsWith('Z');
|
|
109
|
+
if (isNaN(hour) || isNaN(minute) || isNaN(second)) {
|
|
110
|
+
throw new TypeError('Invalid time');
|
|
111
|
+
}
|
|
112
|
+
return DateTime.create(year, month, day, hour, minute, second, utc);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
return DateTime.create(year, month, day);
|
|
85
116
|
}
|
|
86
|
-
return DateTime.create(year, month, day, hour, minute, second, utc);
|
|
87
117
|
}
|
|
88
118
|
/** @internal */
|
|
89
119
|
static fromNumeric(numeric) {
|
|
90
120
|
return new DateTime(numeric);
|
|
91
121
|
}
|
|
92
122
|
toPlain(options) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
123
|
+
let plain;
|
|
124
|
+
if (this.time) {
|
|
125
|
+
plain = options?.stripUtc
|
|
126
|
+
? {
|
|
127
|
+
year: this.year,
|
|
128
|
+
month: this.month,
|
|
129
|
+
day: this.day,
|
|
130
|
+
hour: this.time.hour,
|
|
131
|
+
minute: this.time.minute,
|
|
132
|
+
second: this.time.second,
|
|
133
|
+
}
|
|
134
|
+
: {
|
|
135
|
+
year: this.year,
|
|
136
|
+
month: this.month,
|
|
137
|
+
day: this.day,
|
|
138
|
+
hour: this.time.hour,
|
|
139
|
+
minute: this.time.minute,
|
|
140
|
+
second: this.time.second,
|
|
141
|
+
utc: this.time.utc,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
plain = {
|
|
146
|
+
year: this.year,
|
|
147
|
+
month: this.month,
|
|
148
|
+
day: this.day,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
return plain;
|
|
102
152
|
}
|
|
103
153
|
/**
|
|
104
154
|
* Converts DateTime into ISO 8601 string:
|
|
155
|
+
* * `YYYYMMDD` for date only
|
|
105
156
|
* - `YYYYMMDDTHHMMSSZ` for UTC
|
|
106
157
|
* - `YYYYMMDDTHHMMSS` for local
|
|
107
158
|
*/
|
|
108
159
|
toString() {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
160
|
+
let str = this.year.toString().padStart(4, '0') +
|
|
161
|
+
this.month.toString().padStart(2, '0') +
|
|
162
|
+
this.day.toString().padStart(2, '0');
|
|
163
|
+
if (this.time) {
|
|
164
|
+
str +=
|
|
165
|
+
'T' +
|
|
166
|
+
this.time.hour.toString().padStart(2, '0') +
|
|
167
|
+
this.time.minute.toString().padStart(2, '0') +
|
|
168
|
+
this.time.second.toString().padStart(2, '0') +
|
|
169
|
+
(this.time.utc ? 'Z' : '');
|
|
170
|
+
}
|
|
171
|
+
return str;
|
|
116
172
|
}
|
|
117
173
|
/** @internal */
|
|
118
174
|
toNumeric() {
|
|
119
|
-
return this.numeric;
|
|
175
|
+
return this.state.numeric;
|
|
120
176
|
}
|
|
121
177
|
}
|
|
122
178
|
exports.DateTime = DateTime;
|
package/dist/node/dtstart.d.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import { DateTime, type DateTimeLike } from './datetime';
|
|
2
|
-
export interface DtStartOptions {
|
|
3
|
-
datetime:
|
|
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
4
|
tzid?: string;
|
|
5
5
|
}
|
|
6
|
-
export interface DtStartLike {
|
|
7
|
-
datetime:
|
|
6
|
+
export interface DtStartLike<DT extends DateTimeLike | DateLike> {
|
|
7
|
+
datetime: DT;
|
|
8
8
|
tzid?: string;
|
|
9
9
|
}
|
|
10
|
-
export declare class DtStart {
|
|
11
|
-
readonly datetime:
|
|
10
|
+
export declare class DtStart<DT extends DateTime<Time> | DateTime<undefined> = DateTime<Time>> {
|
|
11
|
+
readonly datetime: DT;
|
|
12
12
|
readonly tzid?: string;
|
|
13
|
-
constructor(datetime:
|
|
14
|
-
constructor(options: DtStartOptions);
|
|
15
|
-
static fromPlain(plain: DtStartLike): DtStart
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
constructor(datetime: DT, 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>;
|
|
19
20
|
}
|
package/dist/node/dtstart.js
CHANGED
|
@@ -20,16 +20,10 @@ class DtStart {
|
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
22
|
setTzid(tzid) {
|
|
23
|
-
return new DtStart(
|
|
24
|
-
datetime: this.datetime,
|
|
25
|
-
tzid,
|
|
26
|
-
});
|
|
23
|
+
return new DtStart(this.datetime, tzid);
|
|
27
24
|
}
|
|
28
25
|
setDatetime(datetime) {
|
|
29
|
-
return new DtStart(
|
|
30
|
-
datetime: datetime,
|
|
31
|
-
tzid: this.tzid,
|
|
32
|
-
});
|
|
26
|
+
return new DtStart(datetime, this.tzid);
|
|
33
27
|
}
|
|
34
28
|
toPlain() {
|
|
35
29
|
return {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DateTime, type Time, type DateTimeLike, type DateLike } from './datetime';
|
|
2
|
+
export interface ExDateOptions<DT extends DateTime<Time> | DateTime<undefined>> {
|
|
3
|
+
values: DT[];
|
|
4
|
+
tzid?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ExDateLike<DT extends DateTimeLike | DateLike> {
|
|
7
|
+
values: DT[];
|
|
8
|
+
tzid?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class ExDate<DT extends DateTime<Time> | DateTime<undefined> = DateTime<Time>> {
|
|
11
|
+
readonly values: DT[];
|
|
12
|
+
readonly tzid?: string;
|
|
13
|
+
constructor(values: DT[], tzid?: string);
|
|
14
|
+
constructor(options: ExDateOptions<DT>);
|
|
15
|
+
static fromPlain(plain: ExDateLike<DateTimeLike>): ExDate<DateTime<Time>>;
|
|
16
|
+
static fromPlain(plain: ExDateLike<DateLike>): ExDate<DateTime<undefined>>;
|
|
17
|
+
setTzid(tzid: string | undefined): ExDate<DT>;
|
|
18
|
+
setValues<NDT extends DateTime<Time> | DateTime<undefined>>(datetimes: NDT[]): ExDate<NDT>;
|
|
19
|
+
toPlain<DTL extends DateTimeLike | DateLike = DT extends DateTime<Time> ? DateTimeLike : DateLike>(): ExDateLike<DTL>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExDate = void 0;
|
|
4
|
+
const datetime_1 = require("./datetime");
|
|
5
|
+
const lib_1 = require("./lib");
|
|
6
|
+
class ExDate {
|
|
7
|
+
constructor(valuesOrOptions, tzid) {
|
|
8
|
+
if (!Array.isArray(valuesOrOptions)) {
|
|
9
|
+
this.values = valuesOrOptions.values;
|
|
10
|
+
this.tzid = valuesOrOptions.tzid;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
this.values = valuesOrOptions;
|
|
14
|
+
this.tzid = tzid;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
static fromRust(rust) {
|
|
21
|
+
const rrule = new this(rust.values.map((dt) => datetime_1.DateTime.fromNumeric(dt)), rust.tzid ?? undefined);
|
|
22
|
+
rrule.rust = rust;
|
|
23
|
+
return rrule;
|
|
24
|
+
}
|
|
25
|
+
static fromPlain(plain) {
|
|
26
|
+
return new this({
|
|
27
|
+
values: plain.values.map((dt) => datetime_1.DateTime.fromPlain(dt)),
|
|
28
|
+
tzid: plain.tzid,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
setTzid(tzid) {
|
|
32
|
+
return new ExDate(this.values, tzid);
|
|
33
|
+
}
|
|
34
|
+
setValues(datetimes) {
|
|
35
|
+
return new ExDate(datetimes, this.tzid);
|
|
36
|
+
}
|
|
37
|
+
toPlain() {
|
|
38
|
+
return {
|
|
39
|
+
values: this.values.map((dt) => dt.toPlain()),
|
|
40
|
+
tzid: this.tzid,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
toRust() {
|
|
47
|
+
this.rust ??= new lib_1.ExDate(this.values.map((dt) => dt.toNumeric()), this.tzid);
|
|
48
|
+
return this.rust;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.ExDate = ExDate;
|
package/dist/node/index.d.ts
CHANGED
package/dist/node/index.js
CHANGED
|
@@ -18,3 +18,5 @@ __exportStar(require("./rrule-set"), exports);
|
|
|
18
18
|
__exportStar(require("./rrule"), exports);
|
|
19
19
|
__exportStar(require("./datetime"), exports);
|
|
20
20
|
__exportStar(require("./dtstart"), exports);
|
|
21
|
+
__exportStar(require("./exdate"), exports);
|
|
22
|
+
__exportStar(require("./rdate"), exports);
|
package/dist/node/lib/index.js
CHANGED
|
@@ -393,6 +393,8 @@ if (!nativeBinding) {
|
|
|
393
393
|
}
|
|
394
394
|
|
|
395
395
|
module.exports = nativeBinding
|
|
396
|
+
module.exports.ExDate = nativeBinding.ExDate
|
|
397
|
+
module.exports.RDate = nativeBinding.RDate
|
|
396
398
|
module.exports.RRule = nativeBinding.RRule
|
|
397
399
|
module.exports.RRuleSet = nativeBinding.RRuleSet
|
|
398
400
|
module.exports.RRuleSetIterator = nativeBinding.RRuleSetIterator
|