-
-
Notifications
You must be signed in to change notification settings - Fork 516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Broken toString() conversion when using string in byweekday parameter #493
Comments
Try using rrulestr #335 (comment) instead |
I have the same problem, and the comment before does not help. RRuleSet takes an RRule still, and the |
seems like the tests in my older PR #371 (that allowed using e.g. |
I'm seeing this too. I've tried both v2.7.0 and v2.7.1 now. For me, the workaround was to always normalise the weekday representations as the import { ByWeekday, RRule, Weekday, WeekdayStr } from "rrule";
import isDefined from "../isDefined"; // this is a type guard
function numberToWeekdayString(input: number): Weekday {
switch (input) {
case 0:
return RRule.MO;
case 1:
return RRule.TU;
case 2:
return RRule.WE;
case 3:
return RRule.TH;
case 4:
return RRule.FR;
case 5:
return RRule.SA;
case 6:
return RRule.SU;
default:
throw `Unknown weekday number ${input}`;
}
}
const WEEKDAY_STRINGS = ["MO", "TU", "WE", "TH", "FR", "SA", "SU"];
function stringToWeekday(input: typeof WEEKDAY_STRINGS[number]): Weekday {
switch (input) {
case "MO":
return RRule.MO;
case "TU":
return RRule.TU;
case "WE":
return RRule.WE;
case "TH":
return RRule.TH;
case "FR":
return RRule.FR;
case "SA":
return RRule.SA;
case "SU":
return RRule.SU;
default:
throw `Unknown weekday number ${input}`;
}
}
type NormaliseByWeekdayInput =
| ByWeekday
| string
| {
weekday: number;
}
| null
| undefined;
export function normaliseByWeekdayItem(
input: NormaliseByWeekdayInput
): Weekday | undefined {
if (!input) return undefined;
if (typeof input === "object") {
return numberToWeekdayString(input.weekday);
}
if (typeof input === "number") {
return numberToWeekdayString(input);
}
if (typeof input === "string") {
return stringToWeekday(input);
}
return input;
}
export function normaliseByWeekday(
input: NormaliseByWeekdayInput | NormaliseByWeekdayInput[]
) {
if (Array.isArray(input))
return input.map(normaliseByWeekdayItem).filter(isDefined);
return normaliseByWeekdayItem(input);
} |
Getting this bug too, Should be fixed either in the code or in the docs but in the meantime, simple fix byweekday: selectedWeekdayStrs.map(b => RRule[b]) |
Reporting an issue
Thank you for taking an interest in
rrule
! Please include the following inyour report:
The text was updated successfully, but these errors were encountered: