Code Monkey home page Code Monkey logo

Comments (9)

rlanvin avatar rlanvin commented on August 28, 2024

Can you provide a code snippet that demonstrates the issue and that I can use to reproduce it?

from php-rrule.

justageek avatar justageek commented on August 28, 2024
    $rule = new RRule('RRULE:FREQ=MONTHLY;INTERVAL=1;BYMONTHDAY=28');
    $next = $rule->getOccurrencesAfter(Carbon::parse('2023-07-28 04:00:33.433843+0000'), false, 1);
    dd($next);

Note this code would have been executed at the date time in the example code, so that affects how the RRule constructor established DTSTART I believe. This is from Laravel thus the use of dd() in a test route to see the output. So, i had to hack in this in your class to simulate what happened on the server:

$this->dtstart = new \DateTime('2023-07-28 04:00:33.433843+0000'); 

from php-rrule.

justageek avatar justageek commented on August 28, 2024

in reality the server code does something like this:

$lastRun = Carbon::now(new DateTimeZone('UTC'));
$nextOccurrences = $rrule->getOccurrencesAfter($lastRun, false, 1);

An when this ran on July 28 at 4AM UTC, the next occurence came out as

2023-09-28 04:00:00

when it should have been

2023-08-28 04:00:00

So in my local testing I hacked in some logging into your trait code to see that it did indeed grab 2 occurences, on for August and one for September, then but slices out the August value for some reason.

from php-rrule.

rlanvin avatar rlanvin commented on August 28, 2024

I tried to reproduce your problem with the following code:

$now = new DateTime('2023-07-28 04:00:33.433843+0000');
$rule = new RRule('RRULE:FREQ=MONTHLY;INTERVAL=1;BYMONTHDAY=28', $now);
$next = $rule->getOccurrencesAfter($now, false, 1);
print_r($next);

And I get the expected result (August):

Array
(
    [0] => DateTime Object
        (
            [date] => 2023-08-28 04:00:33.000000
            [timezone_type] => 1
            [timezone] => +00:00
        )

)

The reason getOccurrencesAfter slices the array when you set you set $inclusive to false (which is the default behaviour) and when $start is a valid occurrence, is because it's just a helper method that calls getOccurrencesBetween($start, null, $limit).

getOccurrencesBetween will always return the bounds if they are also valid occurrences (i.e. it's always inclusive). So if you'd pass a known occurrence to getOccurrencesAfter and set $inclusive to false, and if the array wasn't sliced, then you would always just get the occurrence you passed as a result, which wouldn't be very helpful...

You see here that if you set $inclusive to true or if $date is not an occurrence, then it will not slice anything.

If you say getOccurrencesBetween returned August and September, and August got sliced out, and $inclusive is set to false that can only means that occursAt($date) returned true, which means that you passed the August occurrence to getOccurrencesAfter...

So unless you can provide a code to reproduce the issue in isolation (and that doesn't rely on modifying the library internals), I'm afraid it looks like the problem might be elsewhere in your own code.

I can suggest to make sure you use the latest version of the library just in case.

from php-rrule.

justageek avatar justageek commented on August 28, 2024

Well I'm baffled, I copied your test code and ran it and I still continue to get

    DateTime @1695873633 {#808 ▼
        date: 2023-09-28 04:00:33.0 +00:00
     }

This is with version 2.4.1 unaltered at all.

from php-rrule.

justageek avatar justageek commented on August 28, 2024

Disregard my last comment, I had not properly upgraded to 2.4.1, that appears to fix our problem.

from php-rrule.

rlanvin avatar rlanvin commented on August 28, 2024

Ok glad to hear the latest version works, but that's interesting - I wonder what kind of issue could have caused that behaviour and I don't remember any similar bug. What version were you using before upgrading?

Also feel free to close this ticket if your problem is resolved.

from php-rrule.

justageek avatar justageek commented on August 28, 2024

We were using 2.3.0 before, and it baffles me too as to why it would be different.

from php-rrule.

rlanvin avatar rlanvin commented on August 28, 2024

Ah nice! Then I think you might have encountered this bug that was fixed in 2.3.1: #104

from php-rrule.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.