dtstart vs. Repeat Dates / Current Time Not Considered in Calculation
ccurdt opened this issue · 5 comments
We assume that the current system time is 2023-09-12 09:30 AM.
// 2023-09-12 is a Tuesday
$dateFrom = '2023-09-12 09:00 AM';
$dateTimeObj = DateTime::createFromFormat('Y-m-d H:i A', $dateFrom);
$rrule = new RRule('RRULE:BYDAY=TU;INTERVAL=1;FREQ=WEEKLY;COUNT=3', $dateTimeObj);
foreach ($rrule as $occurrence) {
echo $occurrence->format('D d M Y') . ', ';
}
// Output 1: "Tue 12 Sep 2023, Tue 19 Sep 2023, Tue 26 Sep 2023, "
echo $rrule->humanReadable();
// Output 2: "Weekly on Tuesday, starting from 9/12/23, 3 times"
The output would be correct as it is.
However, the calculation behaves incorrectly when $dateFrom = '2023-09-12 10:00 AM';
. I would have expected the following output:
// Output 1: "Tue 19 Sep 2023, Tue 26 Sep 2023, Tue 03 Oct 2023, "
// Output 2: "Weekly on Tuesday, starting from 9/19/23, 3 times"
Problem: The given dtstart date is in the future and nevertheless a repeat date for the same day is generated.
For me, this looks like an error or how can such things be solved?
Hmm I'm not sure I understand your problem or your reasoning here. If you provide an explicit DTSTART, the current time has absolutely no impact on the way a RRULE is calculated.
Hmm I'm not sure I understand your problem or your reasoning here. If you provide an explicit DTSTART, the current time has absolutely no impact on the way a RRULE is calculated.
RRule generates the repetitions for me with the passed time. See for this
$humanReadable = $rrule->humanReadable([
'date_formatter' => function($date) { return $date->format('r'); },
]);
//Output 2: "weekly on Tuesday, starting from Tue, 12 Sep 2023 09:00:00 +0200, 3 times"
So the time of day is also processed
Other asked: I want exactly 3 repetitions without a self-repeat. Here is an example:
$rSet = new RSet();
// 2023-09-12 is a Tuesday
$dateFrom = '2023-09-12 09:00 AM';
$dateTimeObj = DateTime::createFromFormat('Y-m-d H:i A', $dateFrom);
$rrule = new RRule('RRULE:BYDAY=TU;INTERVAL=1;FREQ=WEEKLY;COUNT=3', $dateTimeObj);
$rSet->addRRule($rrule);
$rSet->addExDate($dateFrom);
$rSet returns me only two repetitions due to the exclusion. But i wish 3 repeats (Tue 19 Sep 2023, Tue 26 Sep 2023, Tue 03 Oct 2023) where today tuesday (Tue 12 Sep 2023) is excluded.
I am still not quite sure what the problem is exactly, why do you start the rule on Tue 12 Sep if you want it excluded? DTSTART is always included as the first occurrence as long as it matches the rule criteria.
Why don't you start the rule on 13 Sep instead?
I don't think you're going at it the right way. Completely removing the ability to work with timezones is a nuclear option that might hide your problem sure, but certainly not solve it.
You need to isolate and clearly describe your problem first. For now based on what you described here, my understanding is that everything is working normally and you have the wrong expectations as to how the calculation should work.