Comments (9)
Can you provide a code snippet that demonstrates the issue and that I can use to reproduce it?
from php-rrule.
$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.
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.
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.
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.
Disregard my last comment, I had not properly upgraded to 2.4.1, that appears to fix our problem.
from php-rrule.
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.
We were using 2.3.0 before, and it baffles me too as to why it would be different.
from php-rrule.
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)
- Humanreadable gets monthly wrong HOT 4
- addExRule not working for me HOT 4
- Drop support for PHP < 7.3 HOT 2
- Daylight Savings Time issue with PHP 8.1 HOT 13
- How to create Rrule for every day from X to Y? HOT 4
- How to use exdate with byhour? HOT 3
- Question: Performance optimization when calculating occurrences using multiple rules HOT 3
- exRule and addRule conflict HOT 3
- More forgiving DTSTART behavior when using only date for UNTIL HOT 2
- Nested exrules HOT 2
- occursAt sometimes failing HOT 2
- Removing all dates that are inside a DatePeriod from Rset HOT 1
- bi-weekly occurance wrong HOT 3
- dtstart vs. Repeat Dates / Current Time Not Considered in Calculation HOT 5
- humanreadable not so much HOT 2
- Looking for a way to add DTEND HOT 1
- Exrul not working
- Add alias methods for better reading of code HOT 1
- Legacy Code - Can I 'require_once' instead of composer ? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-rrule.