rrule-temporal 1.4.0 → 1.4.1

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.cjs CHANGED
@@ -3014,6 +3014,10 @@ function formatTime(hour, minute = 0, second = 0) {
3014
3014
  }
3015
3015
  return `${hr12} ${ampm}`;
3016
3016
  }
3017
+ function weekdayTokenFromZdt(zdt) {
3018
+ const tokens = ["MO", "TU", "WE", "TH", "FR", "SA", "SU"];
3019
+ return tokens[zdt.dayOfWeek - 1];
3020
+ }
3017
3021
  function tzAbbreviation(zdt) {
3018
3022
  const parts = new Intl.DateTimeFormat("en-US", {
3019
3023
  timeZone: zdt.timeZoneId,
@@ -3046,6 +3050,14 @@ function toText(input, locale) {
3046
3050
  rDate,
3047
3051
  exDate
3048
3052
  } = opts;
3053
+ const dayOrLarger = freq === "YEARLY" || freq === "MONTHLY" || freq === "WEEKLY" || freq === "DAILY";
3054
+ const hasExplicitTime = Boolean(byHour || byMinute || bySecond);
3055
+ const dtstartHasTime = opts.dtstart.hour !== 0 || opts.dtstart.minute !== 0 || opts.dtstart.second !== 0;
3056
+ const shouldDefaultTime = dayOrLarger && (hasExplicitTime || dtstartHasTime);
3057
+ const textByDay = byDay != null ? byDay : freq === "WEEKLY" ? [weekdayTokenFromZdt(opts.dtstart)] : void 0;
3058
+ const textByHour = byHour != null ? byHour : shouldDefaultTime ? [opts.dtstart.hour] : void 0;
3059
+ const textByMinute = textByHour ? byMinute != null ? byMinute : [opts.dtstart.minute] : byMinute;
3060
+ const textBySecond = textByHour ? bySecond != null ? bySecond : [opts.dtstart.second] : bySecond;
3049
3061
  const parts = [data.words.every];
3050
3062
  const baseKey = {
3051
3063
  YEARLY: "year",
@@ -3057,7 +3069,7 @@ function toText(input, locale) {
3057
3069
  SECONDLY: "second"
3058
3070
  }[freq];
3059
3071
  const base = data.units[baseKey];
3060
- const daysNormalized = byDay == null ? void 0 : byDay.map((d) => d.toUpperCase());
3072
+ const daysNormalized = textByDay == null ? void 0 : textByDay.map((d) => d.toUpperCase());
3061
3073
  const isWeekdays = daysNormalized && daysNormalized.length === 5 && ["MO", "TU", "WE", "TH", "FR"].every((d) => daysNormalized.includes(d));
3062
3074
  const isEveryday = daysNormalized && daysNormalized.length === 7 && ["MO", "TU", "WE", "TH", "FR", "SA", "SU"].every((d) => daysNormalized.includes(d));
3063
3075
  if (freq === "WEEKLY" && interval === 1 && isWeekdays) {
@@ -3071,15 +3083,15 @@ function toText(input, locale) {
3071
3083
  parts.push(base.singular);
3072
3084
  }
3073
3085
  }
3074
- if (freq === "WEEKLY" && byDay && !isWeekdays && !isEveryday) {
3086
+ if (freq === "WEEKLY" && textByDay && !isWeekdays && !isEveryday) {
3075
3087
  parts.push(
3076
3088
  data.words.on,
3077
- list(byDay, (t) => formatByDayToken(t, data), data.words.and)
3089
+ list(textByDay, (t) => formatByDayToken(t, data), data.words.and)
3078
3090
  );
3079
- } else if (byDay && freq !== "WEEKLY") {
3091
+ } else if (textByDay && freq !== "WEEKLY") {
3080
3092
  parts.push(
3081
3093
  data.words.on,
3082
- list(byDay, (t) => formatByDayToken(t, data), data.words.and)
3094
+ list(textByDay, (t) => formatByDayToken(t, data), data.words.and)
3083
3095
  );
3084
3096
  }
3085
3097
  if (byMonth) {
@@ -3108,18 +3120,18 @@ function toText(input, locale) {
3108
3120
  list(byWeekNo, (n) => n.toString(), data.words.and)
3109
3121
  );
3110
3122
  }
3111
- if (byHour) {
3112
- const minutes = byMinute != null ? byMinute : [0];
3113
- const seconds = bySecond != null ? bySecond : [0];
3114
- const times = byHour.flatMap((h) => minutes.flatMap((m) => seconds.map((s) => formatTime(h, m, s))));
3123
+ if (textByHour) {
3124
+ const minutes = textByMinute != null ? textByMinute : [0];
3125
+ const seconds = textBySecond != null ? textBySecond : [0];
3126
+ const times = textByHour.flatMap((h) => minutes.flatMap((m) => seconds.map((s) => formatTime(h, m, s))));
3115
3127
  parts.push(data.words.at, list(times, void 0, data.words.and));
3116
3128
  parts.push(tzAbbreviation(opts.dtstart));
3117
3129
  }
3118
- if (!byHour && byMinute) {
3119
- parts.push(data.words.at_minute, list(byMinute, void 0, data.words.and));
3130
+ if (!textByHour && textByMinute) {
3131
+ parts.push(data.words.at_minute, list(textByMinute, void 0, data.words.and));
3120
3132
  }
3121
- if (!byHour && !byMinute && bySecond) {
3122
- parts.push(data.words.at_second, list(bySecond, void 0, data.words.and));
3133
+ if (!textByHour && !textByMinute && textBySecond) {
3134
+ parts.push(data.words.at_second, list(textBySecond, void 0, data.words.and));
3123
3135
  }
3124
3136
  if (until) {
3125
3137
  const monthName = data.monthNames[until.month - 1];
package/dist/totext.js CHANGED
@@ -566,6 +566,10 @@ function formatTime(hour, minute = 0, second = 0) {
566
566
  }
567
567
  return `${hr12} ${ampm}`;
568
568
  }
569
+ function weekdayTokenFromZdt(zdt) {
570
+ const tokens = ["MO", "TU", "WE", "TH", "FR", "SA", "SU"];
571
+ return tokens[zdt.dayOfWeek - 1];
572
+ }
569
573
  function tzAbbreviation(zdt) {
570
574
  const parts = new Intl.DateTimeFormat("en-US", {
571
575
  timeZone: zdt.timeZoneId,
@@ -598,6 +602,14 @@ function toText(input, locale) {
598
602
  rDate,
599
603
  exDate
600
604
  } = opts;
605
+ const dayOrLarger = freq === "YEARLY" || freq === "MONTHLY" || freq === "WEEKLY" || freq === "DAILY";
606
+ const hasExplicitTime = Boolean(byHour || byMinute || bySecond);
607
+ const dtstartHasTime = opts.dtstart.hour !== 0 || opts.dtstart.minute !== 0 || opts.dtstart.second !== 0;
608
+ const shouldDefaultTime = dayOrLarger && (hasExplicitTime || dtstartHasTime);
609
+ const textByDay = byDay != null ? byDay : freq === "WEEKLY" ? [weekdayTokenFromZdt(opts.dtstart)] : void 0;
610
+ const textByHour = byHour != null ? byHour : shouldDefaultTime ? [opts.dtstart.hour] : void 0;
611
+ const textByMinute = textByHour ? byMinute != null ? byMinute : [opts.dtstart.minute] : byMinute;
612
+ const textBySecond = textByHour ? bySecond != null ? bySecond : [opts.dtstart.second] : bySecond;
601
613
  const parts = [data.words.every];
602
614
  const baseKey = {
603
615
  YEARLY: "year",
@@ -609,7 +621,7 @@ function toText(input, locale) {
609
621
  SECONDLY: "second"
610
622
  }[freq];
611
623
  const base = data.units[baseKey];
612
- const daysNormalized = byDay == null ? void 0 : byDay.map((d) => d.toUpperCase());
624
+ const daysNormalized = textByDay == null ? void 0 : textByDay.map((d) => d.toUpperCase());
613
625
  const isWeekdays = daysNormalized && daysNormalized.length === 5 && ["MO", "TU", "WE", "TH", "FR"].every((d) => daysNormalized.includes(d));
614
626
  const isEveryday = daysNormalized && daysNormalized.length === 7 && ["MO", "TU", "WE", "TH", "FR", "SA", "SU"].every((d) => daysNormalized.includes(d));
615
627
  if (freq === "WEEKLY" && interval === 1 && isWeekdays) {
@@ -623,15 +635,15 @@ function toText(input, locale) {
623
635
  parts.push(base.singular);
624
636
  }
625
637
  }
626
- if (freq === "WEEKLY" && byDay && !isWeekdays && !isEveryday) {
638
+ if (freq === "WEEKLY" && textByDay && !isWeekdays && !isEveryday) {
627
639
  parts.push(
628
640
  data.words.on,
629
- list(byDay, (t) => formatByDayToken(t, data), data.words.and)
641
+ list(textByDay, (t) => formatByDayToken(t, data), data.words.and)
630
642
  );
631
- } else if (byDay && freq !== "WEEKLY") {
643
+ } else if (textByDay && freq !== "WEEKLY") {
632
644
  parts.push(
633
645
  data.words.on,
634
- list(byDay, (t) => formatByDayToken(t, data), data.words.and)
646
+ list(textByDay, (t) => formatByDayToken(t, data), data.words.and)
635
647
  );
636
648
  }
637
649
  if (byMonth) {
@@ -660,18 +672,18 @@ function toText(input, locale) {
660
672
  list(byWeekNo, (n) => n.toString(), data.words.and)
661
673
  );
662
674
  }
663
- if (byHour) {
664
- const minutes = byMinute != null ? byMinute : [0];
665
- const seconds = bySecond != null ? bySecond : [0];
666
- const times = byHour.flatMap((h) => minutes.flatMap((m) => seconds.map((s) => formatTime(h, m, s))));
675
+ if (textByHour) {
676
+ const minutes = textByMinute != null ? textByMinute : [0];
677
+ const seconds = textBySecond != null ? textBySecond : [0];
678
+ const times = textByHour.flatMap((h) => minutes.flatMap((m) => seconds.map((s) => formatTime(h, m, s))));
667
679
  parts.push(data.words.at, list(times, void 0, data.words.and));
668
680
  parts.push(tzAbbreviation(opts.dtstart));
669
681
  }
670
- if (!byHour && byMinute) {
671
- parts.push(data.words.at_minute, list(byMinute, void 0, data.words.and));
682
+ if (!textByHour && textByMinute) {
683
+ parts.push(data.words.at_minute, list(textByMinute, void 0, data.words.and));
672
684
  }
673
- if (!byHour && !byMinute && bySecond) {
674
- parts.push(data.words.at_second, list(bySecond, void 0, data.words.and));
685
+ if (!textByHour && !textByMinute && textBySecond) {
686
+ parts.push(data.words.at_second, list(textBySecond, void 0, data.words.and));
675
687
  }
676
688
  if (until) {
677
689
  const monthName = data.monthNames[until.month - 1];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rrule-temporal",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
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",