Closed jdumont0201 closed 1 year ago
Hi and sorry for the late response! The combination that you want to use is actually supported, but there's a small mistake in your code: You create one instance of ByWeekDayEntry
and pass your two week days. However, the constructor only takes one weekday – the second parameter is the occurrence
(defaults to null
). E.g., you would write ByWeekDayEntry(DateTime.wednesday, 5)
to express 5WE
(“only on the fifth Wednesday”).
To specify multiple weekdays, write {ByWeekDayEntry(DateTime.wednesday), ByWeekDayEntry(DateTime.friday)}
. Applying this change to your code above yields:
final recurrenceRule = RecurrenceRule(
frequency: Frequency.weekly,
interval: 1,
byWeekDays: {
ByWeekDayEntry(DateTime.wednesday),
ByWeekDayEntry(DateTime.friday),
},
until: DateTime(2022, 10, 1, 0, 0, 0).toUtc(),
);
print(
recurrenceRule.getAllInstances(
start: DateTime(2022, 09, 19, 0, 0, 0).toUtc(),
),
);
// Output: [2022-09-21 22:00:00.000Z, 2022-09-23 22:00:00.000Z, 2022-09-28 22:00:00.000Z, 2022-09-30 22:00:00.000Z]
Also, you should create DateTime
s for this package using DateTime.utc(…)
instead of DateTime(…).toUtc()
, since the latter performs a conversion that is usually not wanted. That's why the output DateTime
s above are not at midnight (since my local timezone is not UTC). When this is fixed, the output looks like Go's output from above (just with different formatting):
final recurrenceRule = RecurrenceRule(
frequency: Frequency.weekly,
interval: 1,
byWeekDays: {
ByWeekDayEntry(DateTime.wednesday),
ByWeekDayEntry(DateTime.friday),
},
until: DateTime.utc(2022, 10, 1, 0, 0, 0),
);
print(
recurrenceRule.getAllInstances(start: DateTime.utc(2022, 09, 19, 0, 0, 0)),
);
// Output: [2022-09-21 00:00:00.000Z, 2022-09-23 00:00:00.000Z, 2022-09-28 00:00:00.000Z, 2022-09-30 00:00:00.000Z]
Describe the bug Combining byWeekDays with weekly throws an assert error, however it is a legit case.
The code
throws
but I believe it is a wrong interpretation of the specification.
Indeed, it must not be specified by a numeric value, but it can be with an array value to describe a usecase like "Repeat every week on Wednesdays and Fridays" as in
Same for count:
Expected result Using another library https://github.com/teambition/rrule-go
yields
which is cover this case correctly.
Environment: