rrule-temporal 1.1.6 → 1.1.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/README.md CHANGED
@@ -224,3 +224,50 @@ const hits = ruleC.between(
224
224
  true
225
225
  );
226
226
  ```
227
+
228
+ ### Converting between **@js-temporal/polyfill** and **temporal-polyfill**
229
+
230
+ `rrule-temporal` ships with **`@js-temporal/polyfill`** and therefore returns `Temporal` objects that are from that implementation. If the rest of your codebase (or a third-party package) relies on the lighter **`temporal-polyfill`** package or a native Temporal implementation, those objects will **not** satisfy `instanceof` checks in your app.
231
+ This snippet shows how to re-hydrate each recurrence result into the polyfill your project expects.
232
+
233
+ ```ts
234
+ // rrule-temporal (and its internals) use @js-temporal/polyfill
235
+ import { Temporal as RRTTemporal } from "@js-temporal/polyfill";
236
+ // your application using temporal-polyfill or native Temporal
237
+ import { Temporal as AppTemporal } from "temporal-polyfill";
238
+
239
+ import { RRuleTemporal } from "rrule-temporal";
240
+
241
+ /** Weekly rule that fires 4 times starting 5 May 2025, 10 AM America/Chicago. */
242
+ const rule = new RRuleTemporal({
243
+ freq: "WEEKLY",
244
+ count: 4,
245
+ dtstart: RRTTemporal.ZonedDateTime.from(
246
+ "2025-05-05T10:00[America/Chicago]"
247
+ ),
248
+ });
249
+
250
+ // Occurrences are ZonedDateTime instances from @js-temporal/polyfill
251
+ const rawOccurrences = rule.all();
252
+
253
+ /** Convert each ZonedDateTime to temporal-polyfill ZonedDateTime. */
254
+ const appOccurrences = rawOccurrences.map((zdt) =>
255
+ AppTemporal.ZonedDateTime.from(zdt.toString())
256
+ );
257
+
258
+ // …now `appOccurrences` can be passed anywhere that expects temporal-polyfill in your app
259
+ ```
260
+
261
+ #### Why `.toString()`?
262
+
263
+ `Temporal.*.from()` accepts ISO 8601 strings (including bracketed time-zone annotations), so calling `toString()` sidesteps the internal-slot branding that makes polyfill objects incompatible.
264
+
265
+ #### Nanosecond precision variant
266
+
267
+ ```ts
268
+ const appOccurrences = rawOccurrences.map((zdt) =>
269
+ AppTemporal.ZonedDateTime.fromEpochNanoseconds(zdt.epochNanoseconds)
270
+ );
271
+ ```
272
+
273
+ Both approaches preserve the original calendar, time-zone and nanosecond accuracy.
@@ -1166,14 +1166,44 @@ var RRuleTemporal = class _RRuleTemporal {
1166
1166
  * @returns An array of Temporal.ZonedDateTime objects representing all occurrences of the rule within the specified time window.
1167
1167
  */
1168
1168
  between(after, before, inc = false) {
1169
+ var _a;
1169
1170
  const startInst = after instanceof Date ? Temporal.Instant.from(after.toISOString()) : after.toInstant();
1170
1171
  const endInst = before instanceof Date ? Temporal.Instant.from(before.toISOString()) : before.toInstant();
1172
+ const startZdt = Temporal.Instant.from(startInst).toZonedDateTimeISO(this.tzid);
1171
1173
  const beforeZdt = Temporal.Instant.from(endInst).toZonedDateTimeISO(this.tzid);
1172
1174
  const tempOpts = __spreadValues({}, this.opts);
1173
1175
  if (!tempOpts.until || Temporal.ZonedDateTime.compare(beforeZdt, tempOpts.until) < 0) {
1174
1176
  tempOpts.until = beforeZdt;
1175
1177
  }
1176
- delete tempOpts.count;
1178
+ if (tempOpts.count === void 0) {
1179
+ const interval = (_a = tempOpts.interval) != null ? _a : 1;
1180
+ let duration;
1181
+ switch (tempOpts.freq) {
1182
+ case "YEARLY":
1183
+ duration = { years: interval };
1184
+ break;
1185
+ case "MONTHLY":
1186
+ duration = { months: interval };
1187
+ break;
1188
+ case "WEEKLY":
1189
+ duration = { weeks: interval };
1190
+ break;
1191
+ case "DAILY":
1192
+ duration = { days: interval };
1193
+ break;
1194
+ case "HOURLY":
1195
+ duration = { hours: interval };
1196
+ break;
1197
+ case "MINUTELY":
1198
+ duration = { minutes: interval };
1199
+ break;
1200
+ default:
1201
+ duration = { seconds: interval };
1202
+ }
1203
+ const aligned = startZdt.withPlainTime(this.originalDtstart.toPlainTime());
1204
+ const candidate = aligned.subtract(duration);
1205
+ tempOpts.dtstart = Temporal.ZonedDateTime.compare(candidate, this.opts.dtstart) > 0 ? candidate : this.opts.dtstart;
1206
+ }
1177
1207
  const tempRule = new _RRuleTemporal(tempOpts);
1178
1208
  const allDates = tempRule.all();
1179
1209
  return allDates.filter((date) => {
package/dist/index.cjs CHANGED
@@ -1187,14 +1187,44 @@ var RRuleTemporal = class _RRuleTemporal {
1187
1187
  * @returns An array of Temporal.ZonedDateTime objects representing all occurrences of the rule within the specified time window.
1188
1188
  */
1189
1189
  between(after, before, inc = false) {
1190
+ var _a;
1190
1191
  const startInst = after instanceof Date ? import_polyfill.Temporal.Instant.from(after.toISOString()) : after.toInstant();
1191
1192
  const endInst = before instanceof Date ? import_polyfill.Temporal.Instant.from(before.toISOString()) : before.toInstant();
1193
+ const startZdt = import_polyfill.Temporal.Instant.from(startInst).toZonedDateTimeISO(this.tzid);
1192
1194
  const beforeZdt = import_polyfill.Temporal.Instant.from(endInst).toZonedDateTimeISO(this.tzid);
1193
1195
  const tempOpts = __spreadValues({}, this.opts);
1194
1196
  if (!tempOpts.until || import_polyfill.Temporal.ZonedDateTime.compare(beforeZdt, tempOpts.until) < 0) {
1195
1197
  tempOpts.until = beforeZdt;
1196
1198
  }
1197
- delete tempOpts.count;
1199
+ if (tempOpts.count === void 0) {
1200
+ const interval = (_a = tempOpts.interval) != null ? _a : 1;
1201
+ let duration;
1202
+ switch (tempOpts.freq) {
1203
+ case "YEARLY":
1204
+ duration = { years: interval };
1205
+ break;
1206
+ case "MONTHLY":
1207
+ duration = { months: interval };
1208
+ break;
1209
+ case "WEEKLY":
1210
+ duration = { weeks: interval };
1211
+ break;
1212
+ case "DAILY":
1213
+ duration = { days: interval };
1214
+ break;
1215
+ case "HOURLY":
1216
+ duration = { hours: interval };
1217
+ break;
1218
+ case "MINUTELY":
1219
+ duration = { minutes: interval };
1220
+ break;
1221
+ default:
1222
+ duration = { seconds: interval };
1223
+ }
1224
+ const aligned = startZdt.withPlainTime(this.originalDtstart.toPlainTime());
1225
+ const candidate = aligned.subtract(duration);
1226
+ tempOpts.dtstart = import_polyfill.Temporal.ZonedDateTime.compare(candidate, this.opts.dtstart) > 0 ? candidate : this.opts.dtstart;
1227
+ }
1198
1228
  const tempRule = new _RRuleTemporal(tempOpts);
1199
1229
  const allDates = tempRule.all();
1200
1230
  return allDates.filter((date) => {
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  RRuleTemporal
3
- } from "./chunk-KT55S4C7.js";
3
+ } from "./chunk-AVNL4A5D.js";
4
4
  export {
5
5
  RRuleTemporal
6
6
  };
package/dist/totext.cjs CHANGED
@@ -1189,14 +1189,44 @@ var RRuleTemporal = class _RRuleTemporal {
1189
1189
  * @returns An array of Temporal.ZonedDateTime objects representing all occurrences of the rule within the specified time window.
1190
1190
  */
1191
1191
  between(after, before, inc = false) {
1192
+ var _a;
1192
1193
  const startInst = after instanceof Date ? import_polyfill.Temporal.Instant.from(after.toISOString()) : after.toInstant();
1193
1194
  const endInst = before instanceof Date ? import_polyfill.Temporal.Instant.from(before.toISOString()) : before.toInstant();
1195
+ const startZdt = import_polyfill.Temporal.Instant.from(startInst).toZonedDateTimeISO(this.tzid);
1194
1196
  const beforeZdt = import_polyfill.Temporal.Instant.from(endInst).toZonedDateTimeISO(this.tzid);
1195
1197
  const tempOpts = __spreadValues({}, this.opts);
1196
1198
  if (!tempOpts.until || import_polyfill.Temporal.ZonedDateTime.compare(beforeZdt, tempOpts.until) < 0) {
1197
1199
  tempOpts.until = beforeZdt;
1198
1200
  }
1199
- delete tempOpts.count;
1201
+ if (tempOpts.count === void 0) {
1202
+ const interval = (_a = tempOpts.interval) != null ? _a : 1;
1203
+ let duration;
1204
+ switch (tempOpts.freq) {
1205
+ case "YEARLY":
1206
+ duration = { years: interval };
1207
+ break;
1208
+ case "MONTHLY":
1209
+ duration = { months: interval };
1210
+ break;
1211
+ case "WEEKLY":
1212
+ duration = { weeks: interval };
1213
+ break;
1214
+ case "DAILY":
1215
+ duration = { days: interval };
1216
+ break;
1217
+ case "HOURLY":
1218
+ duration = { hours: interval };
1219
+ break;
1220
+ case "MINUTELY":
1221
+ duration = { minutes: interval };
1222
+ break;
1223
+ default:
1224
+ duration = { seconds: interval };
1225
+ }
1226
+ const aligned = startZdt.withPlainTime(this.originalDtstart.toPlainTime());
1227
+ const candidate = aligned.subtract(duration);
1228
+ tempOpts.dtstart = import_polyfill.Temporal.ZonedDateTime.compare(candidate, this.opts.dtstart) > 0 ? candidate : this.opts.dtstart;
1229
+ }
1200
1230
  const tempRule = new _RRuleTemporal(tempOpts);
1201
1231
  const allDates = tempRule.all();
1202
1232
  return allDates.filter((date) => {
package/dist/totext.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  RRuleTemporal
3
- } from "./chunk-KT55S4C7.js";
3
+ } from "./chunk-AVNL4A5D.js";
4
4
 
5
5
  // src/totext.ts
6
6
  var en = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rrule-temporal",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
4
4
  "description": "Recurrence rule processing using Temporal PlainDate/PlainDateTime",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
@@ -42,7 +42,7 @@
42
42
  "bugs": {
43
43
  "url": "https://github.com/ggaabe/rrule-temporal/issues"
44
44
  },
45
- "homepage": "https://github.io/ggaabe/rrule-temporal",
45
+ "homepage": "https://ggaabe.github.io/rrule-temporal/",
46
46
  "files": [
47
47
  "dist"
48
48
  ],