rrule-temporal 1.4.6 → 1.5.0

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/totext.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import {
2
- RRuleTemporal
3
- } from "./chunk-6K5NTVS6.js";
2
+ RRuleTemporal,
3
+ allowedWeekdays
4
+ } from "./chunk-S4JPXM4U.js";
4
5
 
5
6
  // src/totext.ts
6
7
  var en = {
@@ -529,6 +530,11 @@ var LOCALES = {};
529
530
  for (const l of active) {
530
531
  if (ALL_LOCALES[l]) LOCALES[l] = ALL_LOCALES[l];
531
532
  }
533
+ var workweekWeekdays = allowedWeekdays.slice(0, 5);
534
+ var byDayTokenRegex = new RegExp(`^([+-]?\\d+)?(${allowedWeekdays.join("|")})$`);
535
+ var weekdayIndexByToken = Object.fromEntries(
536
+ allowedWeekdays.map((weekday, idx) => [weekday, idx])
537
+ );
532
538
  function defaultOrdinal(n) {
533
539
  const abs = Math.abs(n);
534
540
  const suffix = abs % 10 === 1 && abs % 100 !== 11 ? "st" : abs % 10 === 2 && abs % 100 !== 12 ? "nd" : abs % 10 === 3 && abs % 100 !== 13 ? "rd" : "th";
@@ -544,19 +550,11 @@ function list(arr, mapFn = (x) => `${x}`, final) {
544
550
  }
545
551
  function formatByDayToken(tok, locale) {
546
552
  if (typeof tok === "number") return tok.toString();
547
- const m = tok.match(/^([+-]?\d+)?(MO|TU|WE|TH|FR|SA|SU)$/);
553
+ const m = tok.toUpperCase().match(byDayTokenRegex);
548
554
  if (!m) return tok;
549
555
  const ord = m[1] ? parseInt(m[1], 10) : 0;
550
- const weekdayMap = {
551
- MO: 0,
552
- TU: 1,
553
- WE: 2,
554
- TH: 3,
555
- FR: 4,
556
- SA: 5,
557
- SU: 6
558
- };
559
- const idx = weekdayMap[m[2]];
556
+ const weekday = m[2];
557
+ const idx = weekdayIndexByToken[weekday];
560
558
  const name = locale.weekdayNames[idx];
561
559
  if (ord === 0) return name;
562
560
  if (ord === -1) return `${locale.words.last} ${name}`;
@@ -576,8 +574,7 @@ function formatTime(hour, minute = 0, second = 0) {
576
574
  return `${hr12} ${ampm}`;
577
575
  }
578
576
  function weekdayTokenFromZdt(zdt) {
579
- const tokens = ["MO", "TU", "WE", "TH", "FR", "SA", "SU"];
580
- return tokens[zdt.dayOfWeek - 1];
577
+ return allowedWeekdays[zdt.dayOfWeek - 1];
581
578
  }
582
579
  function tzAbbreviation(zdt) {
583
580
  const parts = new Intl.DateTimeFormat("en-US", {
@@ -640,8 +637,8 @@ function toText(input, locale, options = {}) {
640
637
  }[freq];
641
638
  const base = data.units[baseKey];
642
639
  const daysNormalized = textByDay == null ? void 0 : textByDay.map((d) => d.toUpperCase());
643
- const isWeekdays = daysNormalized && daysNormalized.length === 5 && ["MO", "TU", "WE", "TH", "FR"].every((d) => daysNormalized.includes(d));
644
- const isEveryday = daysNormalized && daysNormalized.length === 7 && ["MO", "TU", "WE", "TH", "FR", "SA", "SU"].every((d) => daysNormalized.includes(d));
640
+ const isWeekdays = daysNormalized && daysNormalized.length === workweekWeekdays.length && workweekWeekdays.every((d) => daysNormalized.includes(d));
641
+ const isEveryday = daysNormalized && daysNormalized.length === allowedWeekdays.length && allowedWeekdays.every((d) => daysNormalized.includes(d));
645
642
  if (freq === "WEEKLY" && interval === 1 && isWeekdays) {
646
643
  parts.push(data.words.weekday);
647
644
  } else if (freq === "WEEKLY" && interval === 1 && isEveryday) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rrule-temporal",
3
- "version": "1.4.6",
3
+ "version": "1.5.0",
4
4
  "description": "Recurrence rule (rrule) processing using Temporal PlainDate/PlainDateTime, with cross-timezone and cross-calendar rrule support",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",