rrule-rust 3.0.0-alpha.9 → 3.0.0-next.2
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 +29 -11
- package/dist/browser/cache.d.ts +15 -0
- package/dist/browser/cache.js +44 -0
- package/dist/browser/datetime.d.ts +260 -20
- package/dist/browser/datetime.js +241 -56
- package/dist/browser/dtstart.d.ts +94 -4
- package/dist/browser/dtstart.js +52 -7
- package/dist/browser/exdate.d.ts +105 -1
- package/dist/browser/exdate.js +63 -8
- package/dist/browser/rdate.d.ts +106 -2
- package/dist/browser/rdate.js +63 -8
- package/dist/browser/rrule-set.d.ts +380 -23
- package/dist/browser/rrule-set.js +315 -27
- package/dist/browser/rrule.d.ts +355 -8
- package/dist/browser/rrule.js +250 -3
- package/dist/node/cache.d.ts +15 -0
- package/dist/node/cache.js +48 -0
- package/dist/node/datetime.d.ts +260 -20
- package/dist/node/datetime.js +241 -56
- package/dist/node/dtstart.d.ts +94 -4
- package/dist/node/dtstart.js +52 -7
- package/dist/node/exdate.d.ts +105 -1
- package/dist/node/exdate.js +63 -8
- package/dist/node/lib/index.js +213 -34
- package/dist/node/rdate.d.ts +106 -2
- package/dist/node/rdate.js +63 -8
- package/dist/node/rrule-set.d.ts +380 -23
- package/dist/node/rrule-set.js +315 -27
- package/dist/node/rrule.d.ts +355 -8
- package/dist/node/rrule.js +250 -3
- package/package.json +23 -23
package/dist/browser/datetime.js
CHANGED
|
@@ -1,87 +1,140 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Represents a date and time
|
|
2
|
+
* Represents a date and time, either local or UTC.
|
|
3
|
+
*
|
|
4
|
+
* The generic type parameter `T` determines whether this is:
|
|
5
|
+
* - `DateTime<Time>` - A date with time information
|
|
6
|
+
* - `DateTime<undefined>` - A date without time information
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Create a date-only DateTime
|
|
11
|
+
* const date = DateTime.date(2024, 1, 15);
|
|
12
|
+
* console.log(date.year, date.month, date.day); // 2024, 1, 15
|
|
13
|
+
*
|
|
14
|
+
* // Create a local DateTime
|
|
15
|
+
* const local = DateTime.local(2024, 1, 15, 14, 30, 0);
|
|
16
|
+
* console.log(local.time?.utc); // false
|
|
17
|
+
*
|
|
18
|
+
* // Create a UTC DateTime
|
|
19
|
+
* const utc = DateTime.utc(2024, 1, 15, 14, 30, 0);
|
|
20
|
+
* console.log(utc.time?.utc); // true
|
|
21
|
+
* ```
|
|
3
22
|
*/
|
|
4
23
|
export class DateTime {
|
|
5
|
-
constructor(
|
|
6
|
-
this.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
get year() {
|
|
11
|
-
return (this.state.year ??= Math.floor(this.state.numeric / 100000000000));
|
|
12
|
-
}
|
|
13
|
-
get month() {
|
|
14
|
-
return (this.state.month ??= Math.floor((this.state.numeric / 1000000000) % 100));
|
|
15
|
-
}
|
|
16
|
-
get day() {
|
|
17
|
-
return (this.state.day ??= Math.floor((this.state.numeric / 10000000) % 100));
|
|
18
|
-
}
|
|
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
|
-
}
|
|
24
|
+
constructor(year, month, day, time) {
|
|
25
|
+
this.year = year;
|
|
26
|
+
this.month = month;
|
|
27
|
+
this.day = day;
|
|
28
|
+
this.time = time;
|
|
38
29
|
}
|
|
39
30
|
static create(year, month, day, hour, minute, second, utc) {
|
|
40
|
-
let numeric = year * 100000000000 + month * 1000000000 + day * 10000000;
|
|
41
31
|
if (hour !== undefined &&
|
|
42
32
|
minute !== undefined &&
|
|
43
33
|
second !== undefined &&
|
|
44
34
|
utc !== undefined) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
35
|
+
const dt = new DateTime(year, month, day, {
|
|
36
|
+
hour,
|
|
37
|
+
minute,
|
|
38
|
+
second,
|
|
39
|
+
utc,
|
|
40
|
+
});
|
|
41
|
+
dt.offset = utc ? 0 : undefined;
|
|
42
|
+
return dt;
|
|
50
43
|
}
|
|
51
44
|
else {
|
|
52
|
-
|
|
53
|
-
numeric += 1000;
|
|
54
|
-
numeric += 10;
|
|
55
|
-
numeric += 2;
|
|
56
|
-
return new DateTime(numeric);
|
|
45
|
+
return new DateTime(year, month, day, undefined);
|
|
57
46
|
}
|
|
58
47
|
}
|
|
59
48
|
/**
|
|
60
|
-
* Creates a new DateTime object
|
|
49
|
+
* Creates a new date-only DateTime object (without time information).
|
|
50
|
+
*
|
|
51
|
+
* @param year - Year component (e.g., 2024)
|
|
52
|
+
* @param month - Month component (1-12)
|
|
53
|
+
* @param day - Day component (1-31)
|
|
54
|
+
* @returns A DateTime instance without time information
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* const date = DateTime.date(2024, 1, 15);
|
|
59
|
+
* console.log(date.toString()); // "20240115"
|
|
60
|
+
* ```
|
|
61
61
|
*/
|
|
62
62
|
static date(year, month, day) {
|
|
63
63
|
return this.create(year, month, day);
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
|
+
* Creates a new local DateTime object (with time in local timezone).
|
|
66
67
|
* This method is shorthand for `DateTime.create` with `utc` set to `false`.
|
|
68
|
+
*
|
|
69
|
+
* @param year - Year component (e.g., 2024)
|
|
70
|
+
* @param month - Month component (1-12)
|
|
71
|
+
* @param day - Day component (1-31)
|
|
72
|
+
* @param hour - Hour component (0-23)
|
|
73
|
+
* @param minute - Minute component (0-59)
|
|
74
|
+
* @param second - Second component (0-59)
|
|
75
|
+
* @returns A DateTime instance with local time
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const value = DateTime.local(2024, 1, 15, 14, 30, 0);
|
|
80
|
+
* console.log(value.time.utc); // false
|
|
81
|
+
* console.log(value.toString()); // "20240115T143000"
|
|
82
|
+
* ```
|
|
67
83
|
*/
|
|
68
84
|
static local(year, month, day, hour, minute, second) {
|
|
69
85
|
return DateTime.create(year, month, day, hour, minute, second, false);
|
|
70
86
|
}
|
|
71
87
|
/**
|
|
88
|
+
* Creates a new UTC DateTime object (with time in UTC timezone).
|
|
72
89
|
* This method is shorthand for `DateTime.create` with `utc` set to `true`.
|
|
90
|
+
*
|
|
91
|
+
* @param year - Year component (e.g., 2024)
|
|
92
|
+
* @param month - Month component (1-12)
|
|
93
|
+
* @param day - Day component (1-31)
|
|
94
|
+
* @param hour - Hour component (0-23)
|
|
95
|
+
* @param minute - Minute component (0-59)
|
|
96
|
+
* @param second - Second component (0-59)
|
|
97
|
+
* @returns A DateTime instance with UTC time
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* const value = DateTime.utc(2024, 1, 15, 14, 30, 0);
|
|
102
|
+
* console.log(value.time.utc); // true
|
|
103
|
+
* console.log(value.toString()); // "20240115T143000Z"
|
|
104
|
+
* ```
|
|
73
105
|
*/
|
|
74
106
|
static utc(year, month, day, hour, minute, second) {
|
|
75
107
|
return DateTime.create(year, month, day, hour, minute, second, true);
|
|
76
108
|
}
|
|
77
109
|
static fromPlain(plain) {
|
|
78
110
|
if ('hour' in plain) {
|
|
79
|
-
return DateTime.create(plain.year, plain.month, plain.day, plain.hour, plain.minute, plain.second, plain.utc);
|
|
111
|
+
return DateTime.create(plain.year, plain.month, plain.day, plain.hour, plain.minute, plain.second, plain.utc ?? false);
|
|
80
112
|
}
|
|
81
113
|
return DateTime.create(plain.year, plain.month, plain.day);
|
|
82
114
|
}
|
|
83
115
|
/**
|
|
84
|
-
* Creates a new DateTime object from
|
|
116
|
+
* Creates a new DateTime object from a string representation according to RFC 5545.
|
|
117
|
+
*
|
|
118
|
+
* Supported formats:
|
|
119
|
+
* - `YYYYMMDD` - Date only (e.g., "20240115")
|
|
120
|
+
* - `YYYYMMDDTHHMMSS` - Local date-time (e.g., "20240115T143000")
|
|
121
|
+
* - `YYYYMMDDTHHMMSSZ` - UTC date-time (e.g., "20240115T143000Z")
|
|
122
|
+
*
|
|
123
|
+
* @param str - The RFC 5545 formatted string
|
|
124
|
+
* @returns A DateTime instance
|
|
125
|
+
* @throws {TypeError} If the string format is invalid
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* // Parse date only
|
|
130
|
+
* const date = DateTime.fromString("20240115");
|
|
131
|
+
*
|
|
132
|
+
* // Parse local date-time
|
|
133
|
+
* const local = DateTime.fromString("20240115T143000");
|
|
134
|
+
*
|
|
135
|
+
* // Parse UTC date-time
|
|
136
|
+
* const utc = DateTime.fromString("20240115T143000Z");
|
|
137
|
+
* ```
|
|
85
138
|
*/
|
|
86
139
|
// TODO: add template expression
|
|
87
140
|
static fromString(str) {
|
|
@@ -113,8 +166,53 @@ export class DateTime {
|
|
|
113
166
|
}
|
|
114
167
|
}
|
|
115
168
|
/** @internal */
|
|
116
|
-
static
|
|
117
|
-
|
|
169
|
+
static fromNumbers(year, month, day, hour, minute, second, offset) {
|
|
170
|
+
const dt = new DateTime(year, month, day, hour !== -1
|
|
171
|
+
? {
|
|
172
|
+
hour,
|
|
173
|
+
minute,
|
|
174
|
+
second,
|
|
175
|
+
utc: offset === 0,
|
|
176
|
+
}
|
|
177
|
+
: undefined);
|
|
178
|
+
dt.offset = offset === -1 ? undefined : offset;
|
|
179
|
+
return dt;
|
|
180
|
+
}
|
|
181
|
+
/** @internal */
|
|
182
|
+
static fromInt32Array(arr) {
|
|
183
|
+
return this.fromNumbers(arr[0], arr[1], arr[2], arr[3], arr[4], arr[5], arr[6]);
|
|
184
|
+
}
|
|
185
|
+
/** @internal */
|
|
186
|
+
static fromFlatInt32Array(raw) {
|
|
187
|
+
const result = [];
|
|
188
|
+
for (let i = 0; i < raw.length; i += 7) {
|
|
189
|
+
result.push(this.fromNumbers(raw[i], raw[i + 1], raw[i + 2], raw[i + 3], raw[i + 4], raw[i + 5], raw[i + 6]));
|
|
190
|
+
}
|
|
191
|
+
return result;
|
|
192
|
+
}
|
|
193
|
+
/** @internal */
|
|
194
|
+
static toFlatInt32Array(datetimes) {
|
|
195
|
+
const arr = new Int32Array(datetimes.length * 7);
|
|
196
|
+
for (let i = 0; i < datetimes.length; i++) {
|
|
197
|
+
const dt = datetimes[i];
|
|
198
|
+
const offset = i * 7;
|
|
199
|
+
arr[offset] = dt.year;
|
|
200
|
+
arr[offset + 1] = dt.month;
|
|
201
|
+
arr[offset + 2] = dt.day;
|
|
202
|
+
if (dt.time) {
|
|
203
|
+
arr[offset + 3] = dt.time.hour;
|
|
204
|
+
arr[offset + 4] = dt.time.minute;
|
|
205
|
+
arr[offset + 5] = dt.time.second;
|
|
206
|
+
arr[offset + 6] = dt.offset ?? -1;
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
arr[offset + 3] = -1;
|
|
210
|
+
arr[offset + 4] = -1;
|
|
211
|
+
arr[offset + 5] = -1;
|
|
212
|
+
arr[offset + 6] = -1;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return arr;
|
|
118
216
|
}
|
|
119
217
|
toPlain(options) {
|
|
120
218
|
let plain;
|
|
@@ -148,10 +246,26 @@ export class DateTime {
|
|
|
148
246
|
return plain;
|
|
149
247
|
}
|
|
150
248
|
/**
|
|
151
|
-
* Converts DateTime into
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
* - `
|
|
249
|
+
* Converts the DateTime into an RFC 5545 formatted string.
|
|
250
|
+
*
|
|
251
|
+
* Format depends on the DateTime type:
|
|
252
|
+
* - `YYYYMMDD` for date only
|
|
253
|
+
* - `YYYYMMDDTHHMMSSZ` for UTC date-time
|
|
254
|
+
* - `YYYYMMDDTHHMMSS` for local date-time
|
|
255
|
+
*
|
|
256
|
+
* @returns An RFC 5545 formatted string
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* ```typescript
|
|
260
|
+
* const date = DateTime.date(2024, 1, 15);
|
|
261
|
+
* console.log(date.toString()); // "20240115"
|
|
262
|
+
*
|
|
263
|
+
* const local = DateTime.local(2024, 1, 15, 14, 30, 0);
|
|
264
|
+
* console.log(local.toString()); // "20240115T143000"
|
|
265
|
+
*
|
|
266
|
+
* const utc = DateTime.utc(2024, 1, 15, 14, 30, 0);
|
|
267
|
+
* console.log(utc.toString()); // "20240115T143000Z"
|
|
268
|
+
* ```
|
|
155
269
|
*/
|
|
156
270
|
toString() {
|
|
157
271
|
let str = this.year.toString().padStart(4, '0') +
|
|
@@ -167,8 +281,79 @@ export class DateTime {
|
|
|
167
281
|
}
|
|
168
282
|
return str;
|
|
169
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* Converts the DateTime to a Unix timestamp in milliseconds.
|
|
286
|
+
*
|
|
287
|
+
* This method requires timezone offset information to be available. The offset
|
|
288
|
+
* is automatically set for:
|
|
289
|
+
* - DateTime instances with `utc: true`
|
|
290
|
+
* - DateTime instances generated by RRule methods (`all`, `between`, or iteration)
|
|
291
|
+
*
|
|
292
|
+
* @returns The Unix timestamp in milliseconds since January 1, 1970 00:00:00 UTC
|
|
293
|
+
* @throws {Error} If timezone offset information is not available
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* ```typescript
|
|
297
|
+
* const utc = DateTime.utc(2024, 1, 15, 14, 30, 0);
|
|
298
|
+
* const timestamp = utc.toTimestamp();
|
|
299
|
+
* console.log(timestamp); // 1705328400000
|
|
300
|
+
*
|
|
301
|
+
* // DateTime from RRule methods have offset information
|
|
302
|
+
* const rrule = new RRule({ freq: Frequency.Daily, dtstart: DateTime.local(2024, 1, 1, 10, 0, 0) });
|
|
303
|
+
* const occurrences = rrule.all();
|
|
304
|
+
* const timestamp2 = occurrences[0].toTimestamp();
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
toTimestamp() {
|
|
308
|
+
if (typeof this.offset === 'undefined') {
|
|
309
|
+
throw new Error('There is no information about time zone offset');
|
|
310
|
+
}
|
|
311
|
+
return this.toMilliseconds();
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Converts the DateTime to a JavaScript Date object.
|
|
315
|
+
*
|
|
316
|
+
* This method requires timezone offset information to be available. The offset
|
|
317
|
+
* is automatically set for:
|
|
318
|
+
* - DateTime instances with `utc: true`
|
|
319
|
+
* - DateTime instances generated by RRule methods (`all`, `between`, or iteration)
|
|
320
|
+
*
|
|
321
|
+
* @returns A JavaScript Date object representing the same moment in time
|
|
322
|
+
* @throws {Error} If timezone offset information is not available
|
|
323
|
+
*
|
|
324
|
+
* @example
|
|
325
|
+
* ```typescript
|
|
326
|
+
* const utc = DateTime.utc(2024, 1, 15, 14, 30, 0);
|
|
327
|
+
* const date = utc.toDate();
|
|
328
|
+
* console.log(date.toISOString()); // "2024-01-15T14:30:00.000Z"
|
|
329
|
+
*
|
|
330
|
+
* // DateTime from RRule methods have offset information
|
|
331
|
+
* const rrule = new RRule({ freq: Frequency.Daily, dtstart: DateTime.utc(2024, 1, 1, 10, 0, 0) });
|
|
332
|
+
* const occurrences = rrule.all();
|
|
333
|
+
* const date2 = occurrences[0].toDate();
|
|
334
|
+
* ```
|
|
335
|
+
*/
|
|
336
|
+
toDate() {
|
|
337
|
+
if (typeof this.offset !== 'number') {
|
|
338
|
+
throw new Error('There is no information about time zone offset');
|
|
339
|
+
}
|
|
340
|
+
return new Date(this.toMilliseconds());
|
|
341
|
+
}
|
|
170
342
|
/** @internal */
|
|
171
|
-
|
|
172
|
-
return
|
|
343
|
+
toInt32Array() {
|
|
344
|
+
return new Int32Array([
|
|
345
|
+
this.year,
|
|
346
|
+
this.month,
|
|
347
|
+
this.day,
|
|
348
|
+
this.time ? this.time.hour : -1,
|
|
349
|
+
this.time ? this.time.minute : -1,
|
|
350
|
+
this.time ? this.time.second : -1,
|
|
351
|
+
this.offset ?? -1,
|
|
352
|
+
]);
|
|
353
|
+
}
|
|
354
|
+
toMilliseconds() {
|
|
355
|
+
let time = Date.UTC(this.year, this.month - 1, this.day, this.time?.hour ?? 0, this.time?.minute ?? 0, this.time?.second ?? 0);
|
|
356
|
+
time -= (this.offset ?? 0) * 1000;
|
|
357
|
+
return time;
|
|
173
358
|
}
|
|
174
359
|
}
|
|
@@ -1,20 +1,110 @@
|
|
|
1
1
|
import { DateTime, type Time, type DateTimeLike, type DateLike } from './datetime';
|
|
2
|
+
/**
|
|
3
|
+
* Options for creating a DtStart instance.
|
|
4
|
+
*/
|
|
2
5
|
export interface DtStartOptions<DT extends DateTime<Time> | DateTime<undefined>> {
|
|
3
|
-
|
|
6
|
+
/** The start date/time value */
|
|
7
|
+
value: DT;
|
|
8
|
+
/** Optional timezone identifier (e.g., "America/New_York") */
|
|
4
9
|
tzid?: string;
|
|
5
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Plain object representation of DtStart.
|
|
13
|
+
*/
|
|
6
14
|
export interface DtStartLike<DT extends DateTimeLike | DateLike> {
|
|
7
|
-
|
|
15
|
+
/** The start date/time value */
|
|
16
|
+
value: DT;
|
|
17
|
+
/** Optional timezone identifier (e.g., "America/New_York") */
|
|
8
18
|
tzid?: string;
|
|
9
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Represents the start date/time for a recurrence rule (DTSTART property).
|
|
22
|
+
*
|
|
23
|
+
* DtStart defines when the recurrence pattern begins. It can optionally
|
|
24
|
+
* include a timezone identifier for proper timezone handling.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* // Create with DateTime and timezone
|
|
29
|
+
* const dtstart = new DtStart(
|
|
30
|
+
* DateTime.local(2024, 1, 15, 9, 0, 0),
|
|
31
|
+
* "America/New_York"
|
|
32
|
+
* );
|
|
33
|
+
*
|
|
34
|
+
* // Create with options object
|
|
35
|
+
* const dtstart2 = new DtStart({
|
|
36
|
+
* value: DateTime.date(2024, 1, 15),
|
|
37
|
+
* tzid: "Europe/London"
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
10
41
|
export declare class DtStart<DT extends DateTime<Time> | DateTime<undefined> = DateTime<Time>> {
|
|
42
|
+
/** The start date/time value */
|
|
11
43
|
readonly value: DT;
|
|
44
|
+
/** Optional timezone identifier (e.g., "America/New_York") */
|
|
12
45
|
readonly tzid?: string;
|
|
13
|
-
constructor(
|
|
46
|
+
constructor(value: DT, tzid?: string);
|
|
14
47
|
constructor(options: DtStartOptions<DT>);
|
|
48
|
+
/**
|
|
49
|
+
* Creates a DtStart instance from a plain object representation.
|
|
50
|
+
*
|
|
51
|
+
* @param plain - Plain object with date/time and optional timezone
|
|
52
|
+
* @returns A new DtStart instance
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const plain = {
|
|
57
|
+
* value: { year: 2024, month: 1, day: 15, hour: 9, minute: 0, second: 0, utc: false },
|
|
58
|
+
* tzid: "America/New_York"
|
|
59
|
+
* };
|
|
60
|
+
* const dtstart = DtStart.fromPlain(plain);
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
15
63
|
static fromPlain(plain: DtStartLike<DateTimeLike>): DtStart<DateTime<Time>>;
|
|
16
64
|
static fromPlain(plain: DtStartLike<DateLike>): DtStart<DateTime<undefined>>;
|
|
65
|
+
/**
|
|
66
|
+
* Creates a new DtStart instance with a different timezone.
|
|
67
|
+
*
|
|
68
|
+
* @param tzid - Timezone identifier (e.g., "America/New_York") or undefined
|
|
69
|
+
* @returns A new DtStart instance with the specified timezone
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const dtstart = new DtStart(DateTime.local(2024, 1, 15, 9, 0, 0));
|
|
74
|
+
* const withTz = dtstart.setTzid("America/New_York");
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
17
77
|
setTzid(tzid: string | undefined): DtStart<DT>;
|
|
78
|
+
/**
|
|
79
|
+
* Creates a new DtStart instance with a different date/time value.
|
|
80
|
+
*
|
|
81
|
+
* @param datetime - The new date/time value
|
|
82
|
+
* @returns A new DtStart instance with the specified value
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* const dtstart = new DtStart(DateTime.date(2024, 1, 15));
|
|
87
|
+
* const newStart = dtstart.setValue(DateTime.local(2024, 2, 1, 10, 0, 0));
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
18
90
|
setValue<NDT extends DateTime<Time> | DateTime<undefined>>(datetime: NDT): DtStart<NDT>;
|
|
19
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Converts the DtStart instance to a plain object representation.
|
|
93
|
+
*
|
|
94
|
+
* @returns A plain object with date/time and optional timezone
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* const dtstart = new DtStart(
|
|
99
|
+
* DateTime.local(2024, 1, 15, 9, 0, 0),
|
|
100
|
+
* "America/New_York"
|
|
101
|
+
* );
|
|
102
|
+
* const plain = dtstart.toPlain();
|
|
103
|
+
* // {
|
|
104
|
+
* // value: { year: 2024, month: 1, day: 15, hour: 9, minute: 0, second: 0, utc: false },
|
|
105
|
+
* // tzid: "America/New_York"
|
|
106
|
+
* // }
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
toPlain(): DtStartLike<DT extends DateTime<Time> ? DateTimeLike : DateLike>;
|
|
20
110
|
}
|
package/dist/browser/dtstart.js
CHANGED
|
@@ -1,30 +1,75 @@
|
|
|
1
1
|
import { DateTime, } from './datetime';
|
|
2
|
+
/**
|
|
3
|
+
* Represents the start date/time for a recurrence rule (DTSTART property).
|
|
4
|
+
*
|
|
5
|
+
* DtStart defines when the recurrence pattern begins. It can optionally
|
|
6
|
+
* include a timezone identifier for proper timezone handling.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Create with DateTime and timezone
|
|
11
|
+
* const dtstart = new DtStart(
|
|
12
|
+
* DateTime.local(2024, 1, 15, 9, 0, 0),
|
|
13
|
+
* "America/New_York"
|
|
14
|
+
* );
|
|
15
|
+
*
|
|
16
|
+
* // Create with options object
|
|
17
|
+
* const dtstart2 = new DtStart({
|
|
18
|
+
* value: DateTime.date(2024, 1, 15),
|
|
19
|
+
* tzid: "Europe/London"
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
2
23
|
export class DtStart {
|
|
3
|
-
constructor(
|
|
4
|
-
if ('
|
|
5
|
-
this.value =
|
|
6
|
-
this.tzid =
|
|
24
|
+
constructor(valueOrOptions, tzid) {
|
|
25
|
+
if ('value' in valueOrOptions) {
|
|
26
|
+
this.value = valueOrOptions.value;
|
|
27
|
+
this.tzid = valueOrOptions.tzid;
|
|
7
28
|
}
|
|
8
29
|
else {
|
|
9
|
-
this.value =
|
|
30
|
+
this.value = valueOrOptions;
|
|
10
31
|
this.tzid = tzid;
|
|
11
32
|
}
|
|
12
33
|
}
|
|
13
34
|
static fromPlain(plain) {
|
|
14
35
|
return new this({
|
|
15
|
-
|
|
36
|
+
value: DateTime.fromPlain(plain.value),
|
|
16
37
|
tzid: plain.tzid,
|
|
17
38
|
});
|
|
18
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Creates a new DtStart instance with a different timezone.
|
|
42
|
+
*
|
|
43
|
+
* @param tzid - Timezone identifier (e.g., "America/New_York") or undefined
|
|
44
|
+
* @returns A new DtStart instance with the specified timezone
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const dtstart = new DtStart(DateTime.local(2024, 1, 15, 9, 0, 0));
|
|
49
|
+
* const withTz = dtstart.setTzid("America/New_York");
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
19
52
|
setTzid(tzid) {
|
|
20
53
|
return new DtStart(this.value, tzid);
|
|
21
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Creates a new DtStart instance with a different date/time value.
|
|
57
|
+
*
|
|
58
|
+
* @param datetime - The new date/time value
|
|
59
|
+
* @returns A new DtStart instance with the specified value
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const dtstart = new DtStart(DateTime.date(2024, 1, 15));
|
|
64
|
+
* const newStart = dtstart.setValue(DateTime.local(2024, 2, 1, 10, 0, 0));
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
22
67
|
setValue(datetime) {
|
|
23
68
|
return new DtStart(datetime, this.tzid);
|
|
24
69
|
}
|
|
25
70
|
toPlain() {
|
|
26
71
|
return {
|
|
27
|
-
|
|
72
|
+
value: this.value.toPlain(),
|
|
28
73
|
tzid: this.tzid,
|
|
29
74
|
};
|
|
30
75
|
}
|
package/dist/browser/exdate.d.ts
CHANGED
|
@@ -1,20 +1,124 @@
|
|
|
1
1
|
import { DateTime, type Time, type DateTimeLike, type DateLike } from './datetime';
|
|
2
|
+
/**
|
|
3
|
+
* Options for creating an ExDate instance.
|
|
4
|
+
*/
|
|
2
5
|
export interface ExDateOptions<DT extends DateTime<Time> | DateTime<undefined>> {
|
|
6
|
+
/** Array of date/time values to exclude from recurrence */
|
|
3
7
|
values: DT[];
|
|
8
|
+
/** Optional timezone identifier (e.g., "America/New_York") */
|
|
4
9
|
tzid?: string;
|
|
5
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Plain object representation of ExDate.
|
|
13
|
+
*/
|
|
6
14
|
export interface ExDateLike<DT extends DateTimeLike | DateLike> {
|
|
15
|
+
/** Array of date/time values to exclude from recurrence */
|
|
7
16
|
values: DT[];
|
|
17
|
+
/** Optional timezone identifier (e.g., "America/New_York") */
|
|
8
18
|
tzid?: string;
|
|
9
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Represents exception dates (EXDATE property) for a recurrence rule.
|
|
22
|
+
*
|
|
23
|
+
* ExDate specifies date/time values that should be excluded from the
|
|
24
|
+
* recurrence set. This is useful for marking exceptions like holidays
|
|
25
|
+
* or cancelled events in a recurring series.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* // Create with single date
|
|
30
|
+
* const exdate1 = new ExDate(DateTime.date(2024, 1, 15));
|
|
31
|
+
*
|
|
32
|
+
* // Create with multiple dates
|
|
33
|
+
* const exdate2 = new ExDate([
|
|
34
|
+
* DateTime.date(2024, 1, 15),
|
|
35
|
+
* DateTime.date(2024, 1, 22)
|
|
36
|
+
* ]);
|
|
37
|
+
*
|
|
38
|
+
* // Create with timezone
|
|
39
|
+
* const exdate3 = new ExDate({
|
|
40
|
+
* values: [DateTime.local(2024, 1, 15, 9, 0, 0)],
|
|
41
|
+
* tzid: "America/New_York"
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
10
45
|
export declare class ExDate<DT extends DateTime<Time> | DateTime<undefined> = DateTime<Time>> {
|
|
46
|
+
/** Array of date/time values to exclude from recurrence */
|
|
11
47
|
readonly values: DT[];
|
|
48
|
+
/** Optional timezone identifier (e.g., "America/New_York") */
|
|
12
49
|
readonly tzid?: string;
|
|
50
|
+
constructor(values: DT, tzid?: string);
|
|
13
51
|
constructor(values: DT[], tzid?: string);
|
|
14
52
|
constructor(options: ExDateOptions<DT>);
|
|
53
|
+
/**
|
|
54
|
+
* Creates an ExDate instance from a plain object representation.
|
|
55
|
+
*
|
|
56
|
+
* @param plain - Plain object with date/time values and optional timezone
|
|
57
|
+
* @returns A new ExDate instance
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const plain = {
|
|
62
|
+
* values: [
|
|
63
|
+
* { year: 2024, month: 1, day: 15 },
|
|
64
|
+
* { year: 2024, month: 1, day: 22 }
|
|
65
|
+
* ],
|
|
66
|
+
* tzid: "America/New_York"
|
|
67
|
+
* };
|
|
68
|
+
* const exdate = ExDate.fromPlain(plain);
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
15
71
|
static fromPlain(plain: ExDateLike<DateTimeLike>): ExDate<DateTime<Time>>;
|
|
16
72
|
static fromPlain(plain: ExDateLike<DateLike>): ExDate<DateTime<undefined>>;
|
|
73
|
+
/**
|
|
74
|
+
* Creates a new ExDate instance with a different timezone.
|
|
75
|
+
*
|
|
76
|
+
* @param tzid - Timezone identifier (e.g., "America/New_York") or undefined
|
|
77
|
+
* @returns A new ExDate instance with the specified timezone
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* const exdate = new ExDate([DateTime.date(2024, 1, 15)]);
|
|
82
|
+
* const withTz = exdate.setTzid("America/New_York");
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
17
85
|
setTzid(tzid: string | undefined): ExDate<DT>;
|
|
86
|
+
/**
|
|
87
|
+
* Creates a new ExDate instance with different date/time values.
|
|
88
|
+
*
|
|
89
|
+
* @param datetimes - Array of new date/time values
|
|
90
|
+
* @returns A new ExDate instance with the specified values
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* const exdate = new ExDate([DateTime.date(2024, 1, 15)]);
|
|
95
|
+
* const updated = exdate.setValues([
|
|
96
|
+
* DateTime.date(2024, 1, 15),
|
|
97
|
+
* DateTime.date(2024, 1, 22)
|
|
98
|
+
* ]);
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
18
101
|
setValues<NDT extends DateTime<Time> | DateTime<undefined>>(datetimes: NDT[]): ExDate<NDT>;
|
|
19
|
-
|
|
102
|
+
/**
|
|
103
|
+
* Converts the ExDate instance to a plain object representation.
|
|
104
|
+
*
|
|
105
|
+
* @returns A plain object with date/time values and optional timezone
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* const exdate = new ExDate(
|
|
110
|
+
* [DateTime.date(2024, 1, 15), DateTime.date(2024, 1, 22)],
|
|
111
|
+
* "America/New_York"
|
|
112
|
+
* );
|
|
113
|
+
* const plain = exdate.toPlain();
|
|
114
|
+
* // {
|
|
115
|
+
* // values: [
|
|
116
|
+
* // { year: 2024, month: 1, day: 15 },
|
|
117
|
+
* // { year: 2024, month: 1, day: 22 }
|
|
118
|
+
* // ],
|
|
119
|
+
* // tzid: "America/New_York"
|
|
120
|
+
* // }
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
toPlain(): DT extends DateTime<Time> ? ExDateLike<DateTimeLike> : ExDateLike<DateLike>;
|
|
20
124
|
}
|