Skip to content
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

getting instances for rrule yearly, 'every 2nd tuesday of January' fails #29

Closed
GoldenSoju opened this issue Jan 3, 2022 · 1 comment
Assignees
Labels
T: Fix Type: Build & CI

Comments

@GoldenSoju
Copy link

GoldenSoju commented Jan 3, 2022

When requesting all instances for Rrule 'RRULE:FREQ=YEARLY;COUNT=4;INTERVAL=1;BYDAY=2TU;BYMONTH=1',
it fails with error message:

"The BYDAY rule part MUST NOT be specified with a numeric value when '
'the FREQ rule part is not set to MONTHLY or YEARLY." '
'— https://tools.ietf.org/html/rfc5545#section-3.3.10',

However, it seems to be a legit rrule. (Tested also with (https://jakubroztocil.github.io/rrule/) )

Error is in src/iteration/date_set_filtering.dart
Beginning from line 64 (_isFilteredByWeekDays);

if (rrule.frequency == Frequency.yearly && rrule.byMonths.isEmpty)
-> I think byMonths can be deleted here as this seems to be the reason. It works fine without it.
But I am not sure if there is a specific reason?

You can also test with below:

void main() {
  group('instancesAndRruleToRruleString', () {
    test('yearly every second Tuesday of January (for 4 years)', () {
      final rrule = RecurrenceRule(
          frequency: Frequency.yearly,
          count: 4,
          interval: 1,
          byMonths: {1},
          byWeekDays: {ByWeekDayEntry(DateTime.tuesday, 2)});

      final rruleString = rrule.toString();
      print('RRULE_STRING: $rruleString');

      final instances = rrule.getAllInstances(start: DateTime.now().toUtc());
      print('RRULE_INSTANCES: $instances');
      expect(rruleString,
          'RRULE:FREQ=YEARLY;COUNT=4;INTERVAL=1;BYDAY=2TU;BYMONTH=1');
    });
  });
}
@GoldenSoju GoldenSoju added the T: Fix Type: Build & CI label Jan 3, 2022
@GoldenSoju GoldenSoju changed the title getting instances for rrule yearly, 'every 2nd tuesday of January getting instances for rrule yearly, 'every 2nd tuesday of January' fails Jan 3, 2022
@JonasWanke JonasWanke self-assigned this Jan 4, 2022
@JonasWanke
Copy link
Owner

Thanks for all the details and the reproduction test! It turns out that the second part of the condition (rrule.byMonths.isEmpty) is relevant, but I forgot to handle the other case:

With the frequency set to yearly, something like 2TU means the second Tuesday of the year. However, when byMonths/BYMONTH is also specified (e.g., 1,4), 2TU means the second Tuesday of any of the specified months (e.g., the second Tuesday of January and the second Tuesday of April).

I fixed this in 8646af1 which is published as part of v0.2.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: Fix Type: Build & CI
Projects
None yet
Development

No branches or pull requests

2 participants