use InfyOm\LaravelCalendarEvents\CalendarEvent;
use InfyOm\LaravelCalendarEvents\CalendarEventRecurrencePattern;
$event = new CalendarEvent([
[
'id' => 1,
'title' => 'Daily Repeat End on 30 Jan',
'description' => 'Daily Repeat End on 30 Jan',
'start_date' => '2021-01-10',
'end_date' => '2021-01-20', // nullable
'start_time' => '10:00:00',
'end_time' => '12:00:00',
'is_full_day' => false,
'is_recurring' => true,
'location' => 'Surat, India', // extra field. It will be automatically added to meta
'meta' => [
'ticket_required' => true
]
]
]);
$event->recurring_pattern = new CalendarEventRecurrencePattern([
'recurring_type' => RecurringFrequencyType::RECURRING_TYPE_DAILY,
'max_occurrences' => 10, // Maximum 10 Occurrences
'repeat_interval' => 1, // Repeat Daily
'repeat_by_days' => ["MO", "WE", "SU"], // only repeat on Monday, Wednesday and Sunday
'repeat_by_months' => [],
]);
// Retrieve next 5 events. Returns CalendarEvent array.
$event->getNextEvents(5);
// Retrieve all events between 5th Jan to 15th Jan. Returns CalendarEvent array.
$event->getEventsBetween('2021-01-05', '2021-01-15');
// Retrieve next 2 Occurrences. Returns \Recurr\Recurrence array
$event->getNextOccurrences(2);
// If you Laravel Eloquent model matches the field names with above field name
$event = new CalendarEvent($calendarModle);
2021-01-06 // WEDNESDAY
2021-01-10 // SUNDAY
2021-01-11 // MONDAY
2021-01-13 // WEDNESDAY
but you get an empty array.
www@761a074101a4:/var/www$ php artisan tinker
Psy Shell v0.10.8 (PHP 7.4.16 — cli) by Justin Hileman
>>> use InfyOm\LaravelCalendarEvents\CalendarEvent;
>>> use InfyOm\LaravelCalendarEvents\CalendarEventRecurrencePattern;
>>> $event = new CalendarEvent([
... [
... 'id' => 1,
... 'title' => 'Daily Repeat End on 30 Jan',
... 'description' => 'Daily Repeat End on 30 Jan',
... 'start_date' => '2021-01-10',
... 'end_date' => '2021-01-20', // nullable
... 'start_time' => '10:00:00',
... 'end_time' => '12:00:00',
... 'is_full_day' => false,
... 'is_recurring' => true,
... 'location' => 'Surat, India', // extra field. It will be automatically added to meta
... 'meta' => [
... 'ticket_required' => true
... ]
... ]
... ]);
=> InfyOm\LaravelCalendarEvents\CalendarEvent {#4639
+id: null,
+title: null,
+description: null,
+start_date: null,
+end_date: null,
+start_time: null,
+end_time: null,
+is_full_day: null,
+is_recurring: null,
+meta: [
[
"id" => 1,
"title" => "Daily Repeat End on 30 Jan",
"description" => "Daily Repeat End on 30 Jan",
"start_date" => "2021-01-10",
"end_date" => "2021-01-20",
"start_time" => "10:00:00",
"end_time" => "12:00:00",
"is_full_day" => false,
"is_recurring" => true,
"location" => "Surat, India",
"meta" => [
"ticket_required" => true,
],
],
],
+excluded_dates: null,
+recurring_pattern: null,
}
>>> $event->recurring_pattern = new CalendarEventRecurrencePattern([
... 'recurring_type' => "DAILY",
... 'max_occurrences' => 10, // Maximum 10 Occurrences
... 'repeat_interval' => 1, // Repeat Daily
... 'repeat_by_days' => ["MO", "WE", "SU"], // only repeat on Monday, Wednesday and Sunday
... 'repeat_by_months' => [],
... ]);
=> InfyOm\LaravelCalendarEvents\CalendarEventRecurrencePattern {#4655
+event_id: null,
+recurring_type: "DAILY",
+max_occurrences: 10,
+repeat_interval: 1,
+repeat_by_days: [
"MO",
"WE",
"SU",
],
+repeat_by_months: [],
}
>>> $event->getEventsBetween('2021-01-05', '2021-01-15');
=> []
if (empty($this->end_date)) {
$this->end_date = Carbon::parse($endDate);
} else {
if ($this->end_date > $endDate) {
$this->end_date = Carbon::parse($endDate);
}
}
private function applyEndDate(Rule $rule): Rule
{
if (!empty($this->end_date)) {
$endDate = Carbon::parse($this->end_date)->setTimeFromTimeString($this->end_time);
$rule->setUntil($endDate);
}
return $rule;
}
public function setUntil(\DateTimeInterface $until)
{
$this->until = $until;
$this->count = null;
return $this;
}
To fix this problem we just need to add a check to verify that if we don't have a max_occurrences
set, then we can set the end date
if (empty($this->recurring_pattern->max_occurrences)) {
$this->applyEndDate($rule);
}