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

Recurrence rule generates infinite loop even with constraint set #140

Open
tasso85 opened this issue Jan 4, 2018 · 3 comments
Open

Recurrence rule generates infinite loop even with constraint set #140

tasso85 opened this issue Jan 4, 2018 · 3 comments

Comments

@tasso85
Copy link

tasso85 commented Jan 4, 2018

I have the following recurrence rule:

$rule = "FREQ=YEARLY;DTSTART=20180101T000000;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR,SA,SU;BYMONTH=1;BYSETPOS=+1"

The rule should "mean": from the first of January 2018, yearly every first day of January.

When I try to transform it with:

$transformer = new ArrayTransformer(new ArrayTransformerConfig);
$transformer->transform(new Rule($rule), new BetweenConstraint(new Date('2018-01-01 00:00:00'), new Date('2018-12-31 23:59:59'), true), false);

It gets into an infinite loop in which it never tests the constraint and does not honor the transformer "virtual limit".

While I agree that having all seven days listed in the "BYDAY" part is strange, the rule itself should be valid, and I do not understand why it fails; as soon as you remove at least one day from the "BYDAY" part, it works properly.

@tasso85
Copy link
Author

tasso85 commented Jan 4, 2018

I stand corrected, I tried a slightly different rule:

FREQ=YEARLY;DTSTART=20180101T000000;BYMONTH=1;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR,SA;BYSETPOS=+1

That is, same as above without sunday, and the generated dates are:

/opt/agews64/www/sandbox.php(9) : eval()'d code:5:
object(Recurr\RecurrenceCollection)[2207]
  private 'elements' (Doctrine\Common\Collections\ArrayCollection) => 
    array (size=732)
      0 => 
        object(Recurr\Recurrence)[742]
          protected 'start' => 
            object(DateTime)[8]
              public 'date' => string '2023-01-02 00:00:00.000000' (length=26)
              public 'timezone_type' => int 3
              public 'timezone' => string 'Europe/Rome' (length=11)
          protected 'end' => 
            object(DateTime)[740]
              public 'date' => string '2023-01-02 00:00:00.000000' (length=26)
              public 'timezone_type' => int 3
              public 'timezone' => string 'Europe/Rome' (length=11)
          protected 'index' => int 1
      1 => 
        object(Recurr\Recurrence)[746]
          protected 'start' => 
            object(DateTime)[10]
              public 'date' => string '2034-01-02 00:00:00.000000' (length=26)
              public 'timezone_type' => int 3
              public 'timezone' => string 'Europe/Rome' (length=11)
          protected 'end' => 
            object(DateTime)[744]
              public 'date' => string '2034-01-02 00:00:00.000000' (length=26)
              public 'timezone_type' => int 3
              public 'timezone' => string 'Europe/Rome' (length=11)
          protected 'index' => int 2
      2 => 
        object(Recurr\Recurrence)[748]
          protected 'start' => 
            object(DateTime)[9]
              public 'date' => string '2040-01-02 00:00:00.000000' (length=26)
              public 'timezone_type' => int 3
              public 'timezone' => string 'Europe/Rome' (length=11)
          protected 'end' => 
            object(DateTime)[747]
              public 'date' => string '2040-01-02 00:00:00.000000' (length=26)
              public 'timezone_type' => int 3
              public 'timezone' => string 'Europe/Rome' (length=11)
          protected 'index' => int 3
      3 => 
        object(Recurr\Recurrence)[750]
          protected 'start' => 
            object(DateTime)[12]
              public 'date' => string '2045-01-02 00:00:00.000000' (length=26)
              public 'timezone_type' => int 3
              public 'timezone' => string 'Europe/Rome' (length=11)
          protected 'end' => 
            object(DateTime)[749]
              public 'date' => string '2045-01-02 00:00:00.000000' (length=26)
              public 'timezone_type' => int 3
              public 'timezone' => string 'Europe/Rome' (length=11)
          protected 'index' => int 4
      [...]
      731 => 
        object(Recurr\Recurrence)[2206]
          protected 'start' => 
            object(DateTime)[741]
              public 'date' => string '7065-01-02 00:00:00.000000' (length=26)
              public 'timezone_type' => int 3
              public 'timezone' => string 'Europe/Rome' (length=11)
          protected 'end' => 
            object(DateTime)[2205]
              public 'date' => string '7065-01-02 00:00:00.000000' (length=26)
              public 'timezone_type' => int 3
              public 'timezone' => string 'Europe/Rome' (length=11)
          protected 'index' => int 732

I really do not understand such result, should the rule simply indicate the first day (excluding sunday) of January each year?

EDIT: changing the "BYSETPOS" to anything different from "+1" seems to work as expected.

@tasso85
Copy link
Author

tasso85 commented Jan 4, 2018

After performing further tests, it seems that the issue is on "YEARLY" rules with "BYMONTH=1", "BYDAY=..." and "BYSETPOS" different from "+1", in fact using for example "BYMONTH=2" the rule works again.

In fact rule FREQ=YEARLY;DTSTART=20180101T000000;BYMONTH=1;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=+1 yields

array (
  0 => '2022-01-03',
  1 => '2023-01-02',
  2 => '2028-01-03',
  3 => '2033-01-03',
  4 => '2034-01-02',
  5 => '2039-01-03',
  6 => '2040-01-02',
  7 => '2045-01-02',
  8 => '2050-01-03',
  9 => '2051-01-02',
  10 => '2056-01-03',
  ...
  731 => '4585-01-03',
)

while rule FREQ=YEARLY;DTSTART=20180101T000000;BYMONTH=2;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=+1 yields

array (
  0 => '2018-02-01',
  1 => '2019-02-01',
  2 => '2020-02-03',
  3 => '2021-02-01',
  4 => '2022-02-01',
  5 => '2023-02-01',
  6 => '2024-02-01',
  7 => '2025-02-03',
  8 => '2026-02-02',
  9 => '2027-02-01',
  10 => '2028-02-01',
  ...
  731 => '2749-02-01',
)

@LeonAlvarez
Copy link

"FREQ=WEEKLY;DTSTART=20200304T153337;DTEND=20200307T192637;INTERVAL=2;BYDAY=TU,WE"

      719 => Recurr\Recurrence^ {#3382 …3}
      720 => Recurr\Recurrence^ {#3384 …3}
      721 => Recurr\Recurrence^ {#3386 …3}
      722 => Recurr\Recurrence^ {#3388 …3}
      723 => Recurr\Recurrence^ {#3390 …3}
      724 => Recurr\Recurrence^ {#3392 …3}
      725 => Recurr\Recurrence^ {#3394 …3}
      726 => Recurr\Recurrence^ {#3396 …3}
      727 => Recurr\Recurrence^ {#3398 …3}
      728 => Recurr\Recurrence^ {#3400 …3}
      729 => Recurr\Recurrence^ {#3402 …3}
      730 => Recurr\Recurrence^ {#3404 …3}
      731 => Recurr\Recurrence^ {#3406 …3}```
Im also getting 732 with this rule, could be related? any idea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants