### Install Recurr with Composer Source: https://github.com/simshaun/recurr/blob/master/README.md The recommended way to install the Recurr library is through Composer. This command adds Recurr as a dependency to your PHP project. ```bash composer require simshaun/recurr ``` -------------------------------- ### Create RRULE Rule Object from String Source: https://github.com/simshaun/recurr/blob/master/README.md Demonstrates how to create a Recurr Rule object by providing an RRULE string, a start date, an optional end date, and the timezone. ```php $timezone = 'America/New_York'; $startDate = new \DateTime('2013-06-12 20:00:00', new \DateTimeZone($timezone)); $endDate = new \DateTime('2013-06-14 20:00:00', new \DateTimeZone($timezone)); // Optional $rule = new \Recurr\Rule('FREQ=MONTHLY;COUNT=5', $startDate, $endDate, $timezone); ``` -------------------------------- ### Monthly Recurring Rule Configuration Source: https://github.com/simshaun/recurr/blob/master/README.md Configures how monthly recurring rules handle months with fewer days than the start date. Enables a fix to ensure correct day-of-month progression. ```php $timezone = 'America/New_York'; $startDate = new \DateTime('2013-01-31 20:00:00', new \DateTimeZone($timezone)); $rule = new \Recurr\Rule('FREQ=MONTHLY;COUNT=5', $startDate, null, $timezone); $transformer = new \Recurr\Transformer\ArrayTransformer(); $transformerConfig = new \Recurr\Transformer\ArrayTransformerConfig(); $transformerConfig->enableLastDayOfMonthFix(); $transformer->setConfig($transformerConfig); print_r($transformer->transform($rule)); ``` -------------------------------- ### RecurrenceCollection Filters Source: https://github.com/simshaun/recurr/blob/master/README.md Chainable helper methods for filtering RecurrenceCollection objects based on start and end dates. The `$inc` parameter controls the inclusion of boundary recurrences. ```php $recurrenceCollection->startsBetween(new \DateTime('2024-01-01'), new \DateTime('2024-01-31')); $recurrenceCollection->startsBefore(new \DateTime('2024-01-31')); $recurrenceCollection->startsAfter(new \DateTime('2024-01-01')); $recurrenceCollection->endsBetween(new \DateTime('2024-01-01'), new \DateTime('2024-01-31')); $recurrenceCollection->endsBefore(new \DateTime('2024-01-31')); $recurrenceCollection->endsAfter(new \DateTime('2024-01-01')); ``` -------------------------------- ### Transform RRULE to DateTime Objects Source: https://github.com/simshaun/recurr/blob/master/README.md Converts a Recurr Rule object into a collection of Recurrence objects, each containing start and end DateTime objects. This uses the ArrayTransformer and has a virtual limit to prevent infinite loops. ```php $transformer = new \Recurr\Transformer\ArrayTransformer(); print_r($transformer->transform($rule)); ``` -------------------------------- ### Programmatically Build RRULE Rule Source: https://github.com/simshaun/recurr/blob/master/README.md Shows how to construct a Recurr Rule object using chained methods for setting frequency, days, until date, and timezone. The resulting RRULE string can be retrieved using getString(). ```php $rule = (new \Recurr\Rule) ->setStartDate($startDate) ->setTimezone($timezone) ->setFreq('DAILY') ->setByDay(['MO', 'TU']) ->setUntil(new \DateTime('2017-12-31')) ; echo $rule->getString(); //FREQ=DAILY;UNTIL=20171231T000000;BYDAY=MO,TU ``` -------------------------------- ### Apply Constraints to Date Transformation Source: https://github.com/simshaun/recurr/blob/master/README.md Demonstrates using a BeforeConstraint to filter the dates generated from an RRULE. Only dates before August 1, 2014, will be included in the resulting collection. ```php $startDate = new \DateTime('2014-06-17 04:00:00'); $rule = new \Recurr\Rule('FREQ=MONTHLY;COUNT=5', $startDate); $transformer = new \Recurr\Transformer\ArrayTransformer(); $constraint = new \Recurr\Transformer\Constraint\BeforeConstraint(new \DateTime('2014-08-01 00:00:00')); print_r($transformer->transform($rule, $constraint)); ``` -------------------------------- ### RRULE to Text Transformation Source: https://github.com/simshaun/recurr/blob/master/README.md Transforms recurrence rules (RRULE) into human-readable text. Supports yearly, monthly, weekly, and daily frequencies. Can optionally use a translator for different locales. ```php $rule = new \Recurr\Rule('FREQ=YEARLY;INTERVAL=2;COUNT=3;', new \DateTime()); $textTransformer = new \Recurr\Transformer\TextTransformer(); echo $textTransformer->transform($rule); ``` ```php $rule = new \Recurr\Rule('FREQ=YEARLY;INTERVAL=2;COUNT=3;', new \DateTime()); $textTransformer = new \Recurr\Transformer\TextTransformer( new \Recurr\Transformer\Translator('de') ); echo $textTransformer->transform($rule); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.