wilianx7 / php-recurring
PHP library to make getting dates easier when working with recurring tasks.
Installs: 27 647
Dependents: 0
Suggesters: 0
Security: 0
Stars: 10
Watchers: 3
Forks: 2
Open Issues: 1
Requires
- php: ^8.1
- nesbot/carbon: ^2.65
- tightenco/collect: ^9.0
Requires (Dev)
- ext-json: *
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-10-25 23:41:06 UTC
README
PHP library to make getting dates easier when working with recurring tasks.
Installation
You can install the package via composer:
composer require wilianx7/php-recurring
Basic usage
- Configuration for every day recurrence ending never:
$recurringConfig = new RecurringConfig(); $recurringConfig->setStartDate(Carbon::create(2019, 12, 26, 8, 0, 0)) ->setFrequencyType(FrequencyTypeEnum::DAY()) ->setFrequencyInterval(1) ->setFrequencyEndType(FrequencyEndTypeEnum::NEVER()) ->setEndDate(Carbon::create(2019, 12, 31, 23, 59, 59)); $datesCollection = RecurringBuilder::forConfig($recurringConfig)->startRecurring();
- Configuration for weekly recurrence (Monday and Sunday) ending after 5 occurrences:
$recurringConfig = new RecurringConfig(); $recurringConfig->setStartDate(Carbon::create(2019, 1, 1, 8, 0, 0)) ->setFrequencyType(FrequencyTypeEnum::WEEK()) ->setFrequencyInterval(1) ->setFrequencyEndType(FrequencyEndTypeEnum::AFTER()) ->setFrequencyEndValue(5) ->setRepeatIn([WeekdayEnum::MONDAY(), WeekdayEnum::SUNDAY()]) ->setEndDate(Carbon::create(2019, 12, 31, 23, 59, 59)); $datesCollection = RecurringBuilder::forConfig($recurringConfig)->startRecurring();
- Configuration for monthly recurrence (day 27) ending in 2019-11-30:
$recurringConfig = new RecurringConfig(); $recurringConfig->setStartDate(Carbon::create(2019, 1, 1, 8, 0, 0)) ->setFrequencyType(FrequencyTypeEnum::MONTH()) ->setFrequencyInterval(1) ->setFrequencyEndType(FrequencyEndTypeEnum::IN()) ->setFrequencyEndValue(Carbon::create(2019, 11, 30)) ->setRepeatIn(27) ->setEndDate(Carbon::create(2019, 12, 31, 23, 59, 59)); $datesCollection = RecurringBuilder::forConfig($recurringConfig)->startRecurring();
- Configuration for yearly recurrence (day 27 and month 10) ending never:
$recurringConfig = new RecurringConfig(); $recurringConfig->setStartDate(Carbon::create(2019, 1, 1, 8, 0, 0)) ->setFrequencyType(FrequencyTypeEnum::MONTH()) ->setFrequencyInterval(1) ->setFrequencyEndType(FrequencyEndTypeEnum::IN()) ->setFrequencyEndValue(Carbon::create(2019, 11, 30)) ->setRepeatIn(['day' => 27, 'month' => 10]) ->setEndDate(Carbon::create(2019, 12, 31, 23, 59, 59)); $datesCollection = RecurringBuilder::forConfig($recurringConfig)->startRecurring();
Recurring Config
- includeStartDate: By default, the start date is not included in the return array, as it assumes that this date is already in use, requiring only the return of subsequent dates. However, you can override this behavior by setting "includeStartDate" property as true.
Recurring Builder
Enums
Testing
./vendor/bin/phpunit (Linux)
.\vendor\bin\phpunit (Windows)