### PHP: Composer Installation for RRULE Library Source: https://github.com/rlanvin/php-rrule/blob/master/README.md Provides the Composer command to install the 'rlanvin/php-rrule' library. This is the recommended installation method via Composer, which automatically handles dependencies and autoloading. ```bash composer require rlanvin/php-rrule ``` -------------------------------- ### PHP: Basic RRULE Generation and Iteration Source: https://github.com/rlanvin/php-rrule/blob/master/README.md Demonstrates how to create an RRULE object in PHP for monthly occurrences with a specific start date and count. It then iterates through the generated occurrences and prints them in a formatted string. Finally, it shows how to get a human-readable string representation of the RRULE. ```php use RRule\RRule; $rrule = new RRule([ 'FREQ' => 'MONTHLY', 'INTERVAL' => 1, 'DTSTART' => '2015-06-01', 'COUNT' => 6 ]); foreach ($rrule as $occurrence) { echo $occurrence->format('D d M Y'),", "; } // Mon 01 Jun 2015, Wed 01 Jul 2015, Sat 01 Aug 2015, Tue 01 Sep 2015, Thu 01 Oct 2015, Sun 01 Nov 2015 echo $rrule->humanReadable(),"\n"; // monthly on the 1st of the month, starting from 01/06/2015, 6 times ``` -------------------------------- ### PHP: Translation Review Script Usage Source: https://github.com/rlanvin/php-rrule/blob/master/README.md Illustrates how to use the provided PHP script to review translations for the RRULE library. It shows examples for specifying a locale to list examples in that language and for testing a specific rule across all available locales. ```bash ./bin/review_translations.php --locale ./bin/review_translations.php --rule "" ``` -------------------------------- ### Create Basic Recurrence Rule in PHP Source: https://context7.com/rlanvin/php-rrule/llms.txt Demonstrates how to create a basic recurrence rule using the RRule constructor with an associative array of parameters. It shows how to iterate through occurrences and get a human-readable description of the rule. Dependencies: RRule class. ```php use RRule\RRule; // Every month on the 1st, 6 times starting from June 1, 2015 $rrule = new RRule([ 'FREQ' => 'MONTHLY', 'INTERVAL' => 1, 'DTSTART' => '2015-06-01', 'COUNT' => 6 ]); foreach ($rrule as $occurrence) { echo $occurrence->format('D d M Y') . "\n"; } // Output: // Mon 01 Jun 2015 // Wed 01 Jul 2015 // Sat 01 Aug 2015 // Tue 01 Sep 2015 // Thu 01 Oct 2015 // Sun 01 Nov 2015 // Get human-readable description echo $rrule->humanReadable() . "\n"; // Output: monthly on the 1st of the month, starting from 01/06/2015, 6 times ``` -------------------------------- ### Create Daily Recurrence Rule (10 occurrences) in PHP Source: https://github.com/rlanvin/php-rrule/wiki/RRule An example of creating a daily recurrence rule that will occur for a specified number of times. It initializes the RRule object with frequency and count, along with a start date. ```php $rrule = new RRule([ 'freq' => 'daily', 'count' => 10, 'dtstart' => '1997-09-02 09:00:00' ]); ``` -------------------------------- ### Create Yearly Recurrence Rule for Specific Month in PHP Source: https://github.com/rlanvin/php-rrule/wiki/RRule An example of setting up a yearly recurrence rule that applies only to a specific month, repeating daily within that month for a number of years. It configures frequency, the target month, days of the week, start date, and an until date. ```php $rrule = new RRule([ 'freq' => 'yearly', 'bymonth' => 1, 'byday' => 'MO,TU,WE,TH,FR,SA,SU', 'dtstart' => '1997-09-02 09:00:00', 'until' => '2000-01-31 09:00:00' ]); ``` -------------------------------- ### Create Hourly and Minutely Recurrence Rules Source: https://context7.com/rlanvin/php-rrule/llms.txt Shows how to define high-frequency recurrence rules for hourly and minutely intervals. Examples include occurrences every few hours a specified number of times, and occurrences at set intervals within specific work hours. It also demonstrates retrieving occurrences and counting them. ```php use RRule\RRule; // Every 3 hours, 8 times $rrule = new RRule([ 'FREQ' => 'HOURLY', 'INTERVAL' => 3, 'COUNT' => 8, 'DTSTART' => '2023-01-01 00:00:00' ]); foreach ($rrule as $occurrence) { echo $occurrence->format('Y-m-d H:i:s') . "\n"; } // Output: // 2023-01-01 00:00:00 // 2023-01-01 03:00:00 // 2023-01-01 06:00:00 // 2023-01-01 09:00:00 // 2023-01-01 12:00:00 // 2023-01-01 15:00:00 // 2023-01-01 18:00:00 // 2023-01-01 21:00:00 // Every 15 minutes during work hours $rrule = new RRule([ 'FREQ' => 'MINUTELY', 'INTERVAL' => 15, 'BYHOUR' => [9, 10, 11, 12, 13, 14, 15, 16, 17], 'DTSTART' => '2023-01-01 09:00:00', 'UNTIL' => '2023-01-01 17:00:00' ]); $slots = $rrule->getOccurrences(); echo "Time slots available: " . count($slots) . "\n"; // 33 slots ``` -------------------------------- ### Create a Basic Recurrence Rule Source: https://context7.com/rlanvin/php-rrule/llms.txt Create recurring dates using the RRule constructor with an associative array of parameters. This method allows for defining the frequency, interval, start date, and count of occurrences. ```APIDOC ## Create a Basic Recurrence Rule ### Description Create recurring dates using the RRule constructor with an associative array of parameters. This method allows for defining the frequency, interval, start date, and count of occurrences. ### Method `__construct(array $options)` ### Parameters #### Request Body (Array) - **FREQ** (string) - Required - The frequency of the recurrence (e.g., 'YEARLY', 'MONTHLY', 'WEEKLY', 'DAILY', 'HOURLY', 'MINUTELY', 'SECONDLY'). - **INTERVAL** (int) - Optional - The interval between recurrences. Defaults to 1. - **COUNT** (int) - Optional - The total number of occurrences. - **UNTIL** (string|DateTime) - Optional - The end date for the recurrence. - **DTSTART** (string|DateTime) - Optional - The start date and time of the recurrence. - **WKST** (string) - Optional - The start day of the week (e.g., 'SU', 'MO'). - **BYMONTH** (int|array) - Optional - Specifies months of the year. - **BYMONTHDAY** (int|array) - Optional - Specifies days of the month. - **BYDAY** (string|array) - Optional - Specifies days of the week (e.g., 'MO', 'TU', '1MO'). - **BYSETPOS** (int|array) - Optional - Specifies the occurrence number within a period. ### Request Example ```php use RRule\RRule; // Every month on the 1st, 6 times starting from June 1, 2015 $rrule = new RRule([ 'FREQ' => 'MONTHLY', 'INTERVAL' => 1, 'DTSTART' => '2015-06-01', 'COUNT' => 6 ]); ``` ### Response #### Success Response (Object) - **RRule Object** - An instance of the RRule class representing the defined recurrence rule. #### Response Example ```php // Iterate through occurrences foreach ($rrule as $occurrence) { echo $occurrence->format('D d M Y') . "\n"; } // Output: // Mon 01 Jun 2015 // Wed 01 Jul 2015 // Sat 01 Aug 2015 // Tue 01 Sep 2015 // Thu 01 Oct 2015 // Sun 01 Nov 2015 // Get human-readable description echo $rrule->humanReadable() . "\n"; // Output: monthly on the 1st of the month, starting from 01/06/2015, 6 times ``` ``` -------------------------------- ### Weekly Recurrence Rule with Specific Days in PHP Source: https://context7.com/rlanvin/php-rrule/llms.txt Illustrates how to create weekly recurrence rules that occur on specific days of the week. This example demonstrates setting the frequency to WEEKLY, specifying BYDAY for the desired days, and setting an interval. It also shows how to iterate through occurrences and check if a specific date occurs within the rule. Dependencies: RRule class. ```php use RRule\RRule; // Every 2 weeks on Monday, starting now $rrule = new RRule([ 'FREQ' => 'WEEKLY', 'BYDAY' => 'MO', 'INTERVAL' => 2, 'COUNT' => 5, 'DTSTART' => '2023-01-02 09:00:00' ]); // Iterate through occurrences foreach ($rrule as $occurrence) { echo $occurrence->format('r') . "\n"; } // Output: // Mon, 02 Jan 2023 09:00:00 +0000 // Mon, 16 Jan 2023 09:00:00 +0000 // Mon, 30 Jan 2023 09:00:00 +0000 // Mon, 13 Feb 2023 09:00:00 +0000 // Mon, 27 Feb 2023 09:00:00 +0000 // Check if specific date occurs in the rule var_dump($rrule->occursAt('2023-01-16 09:00:00')); // bool(true) var_dump($rrule->occursAt('2023-01-15 09:00:00')); // bool(false) ``` -------------------------------- ### Create Yearly Recurrence Rules with Complex Constraints Source: https://context7.com/rlanvin/php-rrule/llms.txt Illustrates how to define yearly recurrence rules with specific monthly and daily constraints. Examples include occurrences on multiple specific days within certain months each year, and generating all days within a specific month. It also shows how to retrieve occurrences within a date range. ```php use RRule\RRule; // Every year on January 1st, May 15th, and December 25th $rrule = new RRule([ 'FREQ' => 'YEARLY', 'BYMONTH' => [1, 5, 12], 'BYMONTHDAY' => [1, 15, 25], 'DTSTART' => '2023-01-01', 'COUNT' => 15 ]); foreach ($rrule as $occurrence) { echo $occurrence->format('Y-m-d') . "\n"; } // Output: // 2023-01-01, 2023-01-15, 2023-01-25 // 2023-05-01, 2023-05-15, 2023-05-25 // 2023-12-01, 2023-12-15, 2023-12-25 // 2024-01-01, 2024-01-15, 2024-01-25 // 2024-05-01, 2024-05-15, 2024-05-15 // Every year in January (all days) $january = new RRule([ 'FREQ' => 'YEARLY', 'BYMONTH' => 1, 'BYDAY' => 'MO,TU,WE,TH,FR,SA,SU', 'DTSTART' => '2023-01-01', 'UNTIL' => '2025-12-31' ]); $jan_2024 = $january->getOccurrencesBetween('2024-01-01', '2024-01-31'); echo count($jan_2024); // 31 days ``` -------------------------------- ### Complex Monthly Pattern with BYSETPOS in PHP Source: https://context7.com/rlanvin/php-rrule/llms.txt Demonstrates the use of BYSETPOS for creating complex monthly recurrence patterns, specifically to find the last workday of each month. This example sets the frequency to MONTHLY, specifies weekdays with BYDAY, and uses BYSETPOS with -1 to denote the last occurrence. Dependencies: RRule class. ```php use RRule\RRule; // Last workday (Mon-Fri) of each month $rrule = new RRule([ 'FREQ' => 'MONTHLY', 'BYDAY' => 'MO,TU,WE,TH,FR', 'BYSETPOS' => -1, 'DTSTART' => '2023-01-01', 'COUNT' => 12 ]); foreach ($rrule as $occurrence) { echo $occurrence->format('Y-m-d (l)') . "\n"; } // Output: // 2023-01-31 (Tuesday) // 2023-02-28 (Tuesday) // 2023-03-31 (Friday) // 2023-04-28 (Friday) // 2023-05-31 (Wednesday) // ... and so on ``` -------------------------------- ### Get RRule Occurrences Between Dates (PHP) Source: https://github.com/rlanvin/php-rrule/wiki/RRuleInterface Retrieve occurrences within a specified date range (inclusive). Dates can be strings, timestamps, or DateTime objects. If `$begin` is null, occurrences before `$end` are returned. If `$end` is null, occurrences after `$begin` are returned (throws LogicException for infinite rules). If both are null, it acts like getOccurrences(). The `$limit` parameter (>= 1.5) can restrict the number of results. Note that this method returns occurrences based on their start date, not duration. ```php $rrule = new RRule([ 'FREQ' => 'MONTHLY', 'BYDAY' => '1MO', 'DTSTART' => '2016-01-01', 'UNTIL' => '2016-12-31' ]); $result = $rrule->getOccurrencesBetween('2016-01-01', '2016-01-31'); print_r($result); ``` -------------------------------- ### Parse RFC 5545 String to Recurrence Set Source: https://context7.com/rlanvin/php-rrule/llms.txt Demonstrates how to create a complex recurrence set from an RFC 5545 formatted string using the RSet class. This includes handling start times, recurrence rules, exclusion rules, and specific dates. The output shows the resulting occurrences after applying all rules and exclusions. It also shows how to access individual components of the RSet. ```php use RRule\RSet; $rset = new RSet( "DTSTART;TZID=America/New_York:19970901T090000\n" . "RRULE:FREQ=DAILY;COUNT=5\n" . "EXRULE:FREQ=DAILY;INTERVAL=2;COUNT=2\n" . "RDATE;TZID=America/New_York:19970910T090000\n" . "EXDATE;TZID=America/New_York:19970903T090000" ); // This will: // 1. Include daily occurrences for 5 days (Sept 1-5) // 2. Exclude every other day for 2 occurrences (Sept 1, 3) // 3. Add Sept 10 // 4. Exclude Sept 3 // Result: Sept 2, 4, 5, 10 $occurrences = $rset->getOccurrences(); foreach ($occurrences as $date) { echo $date->format('Y-m-d') . "\n"; } // Access RSet components $rules = $rset->getRRules(); // Get all inclusion rules $exrules = $rset->getExRules(); // Get all exclusion rules $dates = $rset->getDates(); // Get all included dates $exdates = $rset->getExDates(); // Get all excluded dates echo "Number of rules: " . count($rules) . "\n"; echo "Number of exclusion rules: " . count($exrules) . "\n"; ``` -------------------------------- ### Weekly Recurrence with Specific Days Source: https://context7.com/rlanvin/php-rrule/llms.txt Create recurring events on specific days of the week with a defined interval and start date. ```APIDOC ## Weekly Recurrence with Specific Days ### Description Create recurring events on specific days of the week with a defined interval and start date. ### Method `__construct(array $options)` ### Parameters #### Request Body (Array) - **FREQ** (string) - Must be 'WEEKLY'. - **BYDAY** (string|array) - Required - Specifies the day(s) of the week (e.g., 'MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU'). - **INTERVAL** (int) - Optional - The interval in weeks between recurrences. Defaults to 1. - **COUNT** (int) - Optional - The total number of occurrences. - **DTSTART** (string|DateTime) - Optional - The start date and time of the recurrence. ### Request Example ```php use RRule\RRule; // Every 2 weeks on Monday, starting now $rrule = new RRule([ 'FREQ' => 'WEEKLY', 'BYDAY' => 'MO', 'INTERVAL' => 2, 'COUNT' => 5, 'DTSTART' => '2023-01-02 09:00:00' ]); ``` ### Response #### Success Response (Object) - **RRule Object** - An instance of the RRule class configured for weekly recurrences. #### Response Example ```php // Iterate through occurrences foreach ($rrule as $occurrence) { echo $occurrence->format('r') . "\n"; } // Output: // Mon, 02 Jan 2023 09:00:00 +0000 // Mon, 16 Jan 2023 09:00:00 +0000 // Mon, 30 Jan 2023 09:00:00 +0000 // Mon, 13 Feb 2023 09:00:00 +0000 // Mon, 27 Feb 2023 09:00:00 +0000 // Check if specific date occurs in the rule var_dump($rrule->occursAt('2023-01-16 09:00:00')); // bool(true) var_dump($rrule->occursAt('2023-01-15 09:00:00')); // bool(false) ``` ``` -------------------------------- ### Cache Management for RRule and RSet Performance Source: https://context7.com/rlanvin/php-rrule/llms.txt Details how to leverage the internal occurrence cache provided by the RRule library to improve performance. It shows how the first call to `getOccurrences()` calculates and caches results, while subsequent calls are significantly faster. The example also demonstrates how to manually clear the cache using `clearCache()` when necessary, and that caching applies to both RRule and RSet objects. ```php use RRule\RRule; $rrule = new RRule([ 'FREQ' => 'DAILY', 'COUNT' => 365, 'DTSTART' => '2023-01-01' ]); // First call calculates and caches occurrences $start = microtime(true); $occurrences1 = $rrule->getOccurrences(); $time1 = microtime(true) - $start; // Second call uses cache (much faster) $start = microtime(true); $occurrences2 = $rrule->getOccurrences(); $time2 = microtime(true) - $start; echo "First call: {$time1}s\n"; echo "Cached call: {$time2}s\n"; // Significantly faster // Clear cache if needed (e.g., memory concerns) $rrule->clearCache(); // Subsequent calls will recalculate $occurrences3 = $rrule->getOccurrences(); // For RSet objects, cache works the same way $rset = new RRule\RSet(); $rset->addRRule(['FREQ' => 'DAILY', 'COUNT' => 100, 'DTSTART' => '2023-01-01']); $rset->getOccurrences(); // Cached $rset->clearCache(); // Clear when needed ``` -------------------------------- ### humanReadable() - Get Human Readable Description Source: https://github.com/rlanvin/php-rrule/wiki/RRule Generates a human-readable description of the recurrence rule. This method can be configured with various options to customize the output, such as locale, date formatting, and inclusion of start/until dates. It produces better results if the PHP `intl` extension is available. ```APIDOC ## humanReadable(array $opt = []) ### Description Produces a human-readable description of the recurrence rule. ### Method `humanReadable` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **opt** (array) - Optional - An array of options to configure the human-readable output. - **locale** (string) - A locale string (e.g., 'en', 'en_GB', 'fr'). Defaults to the current locale. - **fallback** (string|null) - A locale to fallback to if the main language is not found. Defaults to 'en'. Set to `null` to disable fallback. - **date_formatter** (callable) - A function to format `DTSTART` and `UNTIL`. Takes a `DateTime` object and returns a string. - **date_format** (int) - `IntlDateFormatter` constant for date format (e.g., `IntlDateFormatter::SHORT`). Requires `intl` extension. - **time_format** (int) - `IntlDateFormatter` constant for time format (e.g., `IntlDateFormatter::NONE`). Requires `intl` extension. - **explicit_infinite** (bool) - Whether to explicitly state if the rule is infinite. Defaults to `true`. - **include_start** (bool) - Whether to include the start date in the description. Defaults to `true`. - **include_until** (bool) - Whether to include the until date or count in the description. Defaults to `true`. - **custom_path** (string) - Filesystem path to look for custom translations before the default folder. ### Request Example ```php $rule = new RRule('DTSTART;TZID=America/New_York:19970901T090000 RRULE:FREQ=WEEKLY;INTERVAL=2;UNTIL=19971224T000000Z;WKST=SU;BYDAY=MO,WE,FR'); // Basic usage echo $rule->humanReadable(); // With locale option echo $rule->humanReadable(['locale' => 'fr']); // With date format option echo $rule->humanReadable([ 'locale' => 'en_US', 'date_format' => IntlDateFormatter::MEDIUM ]), "\n\n"; // With custom date formatter echo $rule->humanReadable(['date_formatter' => function($date) { return $date->format('r'); }]); ``` ### Response #### Success Response (string) Returns a string containing the human-readable description of the recurrence rule. ``` -------------------------------- ### Create Daily Recurrence Rule Until Specific Date in PHP Source: https://github.com/rlanvin/php-rrule/wiki/RRule Demonstrates creating a daily recurrence rule that continues until a specified end date. The RRule object is configured with frequency, start date, and an until date. ```php $rrule = new RRule([ 'freq' => 'daily', 'dtstart' => '1997-09-02 09:00:00', 'until' => '1997-12-24 00:00:00' ]); ``` -------------------------------- ### Get Nth occurrence after a specific date Source: https://github.com/rlanvin/php-rrule/wiki/RRuleInterface The `getNthOccurrenceAfter` method calculates the Nth occurrence of a recurring event that falls strictly after a given date. This method is available in version 2.0 and later of the library. -------------------------------- ### Get RRule Occurrences Before Date (PHP) Source: https://github.com/rlanvin/php-rrule/wiki/RRuleInterface Return all occurrences of a recurrence rule that fall before a specified date. The `$inclusive` parameter (default false) determines if the specified date itself should be included if it's an occurrence. The `$limit` parameter (available in >= 2.0) can restrict the number of occurrences returned. ```php // Example usage (assuming $rrule is defined): // $rrule->getOccurrencesBefore('2023-12-31', true, 5); ``` -------------------------------- ### Get RFC Compliant String Representation Source: https://github.com/rlanvin/php-rrule/wiki/RRule The `rfcString()` method generates a RFC-compliant string representation of the recurrence rule. By default, it includes timezone information for `DTSTART` and converts `UNTIL` to UTC. With `$include_timezone = false` (versions >= 1.3), `DTSTART` and `UNTIL` are represented as local times without timezone information. ```php // Assuming $rrule is an instance of RRule // Get RFC string with timezone information (default) echo $rrule->rfcString(); // Get RFC string without timezone information (versions >= 1.3) echo $rrule->rfcString(false); ``` -------------------------------- ### Get Nth Occurrence Relative to Date Source: https://context7.com/rlanvin/php-rrule/llms.txt Find specific occurrences before or after a reference date using the RRule class. This function allows fetching the Nth occurrence relative to a given date, including occurrences on, before, or after the specified date. It requires the RRule class. ```php use RRule\RRule; $rrule = new RRule([ 'FREQ' => 'WEEKLY', 'BYDAY' => 'MO', 'DTSTART' => '2023-01-01', 'COUNT' => 52 ]); // Get the 3rd Monday after June 1st $third_after = $rrule->getNthOccurrenceAfter('2023-06-01', 3); echo $third_after->format('Y-m-d') . "\n"; // 2023-06-19 // Get the 2nd Monday before June 1st $second_before = $rrule->getNthOccurrenceBefore('2023-06-01', 2); echo $second_before->format('Y-m-d') . "\n"; // 2023-05-22 // Get occurrence relative to a date (0 = date itself, positive = after, negative = before) $from_date = $rrule->getNthOccurrenceFrom('2023-06-05', 0); // Returns date if it's an occurrence $next = $rrule->getNthOccurrenceFrom('2023-06-05', 1); // Next occurrence $prev = $rrule->getNthOccurrenceFrom('2023-06-05', -1); // Previous occurrence if ($from_date) { echo $from_date->format('Y-m-d') . "\n"; // 2023-06-05 } echo $next->format('Y-m-d') . "\n"; // 2023-06-12 echo $prev->format('Y-m-d') . "\n"; // 2023-05-29 ``` -------------------------------- ### Create Weekly Recurrence Rule with Interval in PHP Source: https://github.com/rlanvin/php-rrule/wiki/RRule Instantiates a new RRule object to define a recurring event. This example sets the frequency to weekly with an interval of 2, and specifies occurrences on Mondays. The 'freq', 'byday', and 'interval' parameters are used to configure the rule. The 'freq' parameter is required and determines the base period of recurrence. ```php $rrule = new RRule\RRule([ 'freq' => 'weekly', 'byday' => 'MO', 'interval' => 2 ]); ``` -------------------------------- ### Array Access for Specific Occurrences in PHP Source: https://context7.com/rlanvin/php-rrule/llms.txt Explains how to access specific occurrences of a recurrence rule by their index, without needing to iterate through all preceding occurrences. This utilizes PHP's array access features for the RRule object. It also demonstrates checking for the existence of an occurrence by index and getting the total count of occurrences. Dependencies: RRule class. ```php use RRule\RRule; $rrule = new RRule([ 'FREQ' => 'DAILY', 'INTERVAL' => 2, 'COUNT' => 10, 'DTSTART' => '1997-09-02 09:00:00' ]); // Access specific occurrences by index (0-based) echo $rrule[0]->format('r') . "\n"; // First occurrence // Tue, 02 Sep 1997 09:00:00 +0000 echo $rrule[4]->format('r') . "\n"; // Fifth occurrence // Wed, 10 Sep 1997 09:00:00 +0000 echo $rrule[9]->format('r') . "\n"; // Last occurrence // Wed, 24 Sep 1997 09:00:00 +0000 // Check if index exists var_dump(isset($rrule[0])); // bool(true) var_dump(isset($rrule[10])); // bool(false) // Count total occurrences echo count($rrule); // 10 ``` -------------------------------- ### Get All RRule Occurrences (PHP) Source: https://github.com/rlanvin/php-rrule/wiki/RRuleInterface Retrieve an array of all occurrences (as DateTime objects) for a recurrence rule. If the rule is infinite (no COUNT or UNTIL), this method throws a LogicException. The `$limit` parameter (available in >= 1.5) can restrict the number of occurrences returned. Objects can also be directly iterated using foreach. ```php $rrule = new RRule([ 'FREQ' => 'DAILY', 'DTSTART' => '2016-01-01', 'UNTIL' => '2016-12-31' ]); $result = $rrule->getOccurrences(); // an array of DateTime objects ``` -------------------------------- ### Get RRule Occurrences After Date (PHP) Source: https://github.com/rlanvin/php-rrule/wiki/RRuleInterface Return all occurrences of a recurrence rule that fall after a specified date. The `$inclusive` parameter (default false) determines if the specified date itself should be included if it's an occurrence. The `$limit` parameter (available in >= 2.0) can restrict the number of occurrences returned. A LogicException is thrown if the rule is infinite and no limit is specified. ```php // Example usage (assuming $rrule is defined): // $rrule->getOccurrencesAfter('2024-01-01', false, 10); ``` -------------------------------- ### Get Nth Occurrence After Source: https://github.com/rlanvin/php-rrule/wiki/RRuleInterface Retrieves the Nth occurrence of a recurring event rule after a specified date. The starting date is not included in the count. ```APIDOC ## `getNthOccurrenceAfter($date, $index)` ### Description Return the Nth occurrence after a date (non inclusive). ### Method GET (Assumed, as it's retrieving data) ### Endpoint `/rrule/getNthOccurrenceAfter` (Assumed) ### Parameters #### Path Parameters None #### Query Parameters - **date** (string|DateTime|int) - Required - The date after which to find the occurrence. - **index** (int) - Required - The index of the occurrence to find (e.g., 1 for the first occurrence). #### Request Body None ### Request Example ```json { "date": "2023-01-01", "index": 5 } ``` ### Response #### Success Response (200) - **occurrence** (string|DateTime) - The date of the Nth occurrence. #### Response Example ```json { "occurrence": "2023-03-15T10:00:00+00:00" } ``` ``` -------------------------------- ### Get Nth Occurrence From Source: https://github.com/rlanvin/php-rrule/wiki/RRuleInterface Retrieves the Nth occurrence of a recurring event rule either before or after a specified date, depending on the sign of the index. The starting date is not included. ```APIDOC ## `getNthOccurrenceFrom($date, $index)` ### Description Return the Nth occurrence before (if `$index` is negative) or after (if `$index` is positive) a date (non inclusive). ### Method GET (Assumed, as it's retrieving data) ### Endpoint `/rrule/getNthOccurrenceFrom` (Assumed) ### Parameters #### Path Parameters None #### Query Parameters - **date** (string|DateTime|int) - Required - The date from which to find the occurrence. - **index** (int) - Required - The index of the occurrence to find. Negative for before, positive for after. #### Request Body None ### Request Example ```json { "date": "2023-01-01", "index": -3 } ``` ### Response #### Success Response (200) - **occurrence** (string|DateTime) - The date of the Nth occurrence. #### Response Example ```json { "occurrence": "2022-10-04T10:00:00+00:00" } ``` ``` -------------------------------- ### Parse RFC String for Recurrence Rule in PHP Source: https://context7.com/rlanvin/php-rrule/llms.txt Shows how to create recurrence rules by parsing RFC 5545 formatted strings. It covers parsing from a full DTSTART and RRULE string, or just the RRULE portion with a provided DTSTART. It also demonstrates retrieving all occurrences and exporting back to an RFC string. Dependencies: RRule class. ```php use RRule\RRule; // From RFC-compliant string with DTSTART and RRULE $rrule = new RRule( "DTSTART;TZID=America/New_York:19970901T090000\n" . "RRULE:FREQ=DAILY;UNTIL=19971224T000000Z;WKST=SU;BYDAY=MO,WE,FR;BYMONTH=1" ); // Or from just the RRULE portion $rrule = new RRule('FREQ=DAILY;COUNT=10', new DateTime('1997-09-02')); // Get all occurrences $occurrences = $rrule->getOccurrences(); foreach ($occurrences as $date) { echo $date->format('Y-m-d H:i:s') . "\n"; } // Export back to RFC string echo $rrule->rfcString(); // Output: DTSTART;TZID=America/New_York:19970901T090000 // RRULE:FREQ=DAILY;UNTIL=19971224T000000Z;WKST=SU;BYDAY=MO,WE,FR;BYMONTH=1 ``` -------------------------------- ### PHP: Autoloader Inclusion Source: https://github.com/rlanvin/php-rrule/blob/master/README.md Shows how to include the Composer autoloader file in a PHP script. This allows the 'rlanvin/php-rrule' library and other Composer-installed dependencies to be automatically available for use. ```php require 'vendor/autoload.php'; ``` -------------------------------- ### Get Nth RRule Occurrence Before Date (PHP) Source: https://github.com/rlanvin/php-rrule/wiki/RRuleInterface Retrieve the Nth occurrence of a recurrence rule that falls before a specified date (non-inclusive). This method is available from version 2.0 onwards. ```php // Example usage (assuming $rrule is defined): // $rrule->getNthOccurrenceBefore('2024-01-01', 3); ``` -------------------------------- ### Handle Infinite Recurrence Rules Safely Source: https://context7.com/rlanvin/php-rrule/llms.txt Explains how to manage recurrence rules that are set to repeat indefinitely. It demonstrates checking if a rule is infinite using `isInfinite()`, safely retrieving a limited number of occurrences using `getOccurrences(limit)` or `getOccurrencesBetween()`, and the necessity of manually breaking loops for infinite rules. It also shows the exception thrown when attempting to retrieve all occurrences of an infinite rule. ```php use RRule\RRule; // Every day, forever (infinite rule) $rrule = new RRule([ 'FREQ' => 'DAILY', 'DTSTART' => '2023-01-01' ]); var_dump($rrule->isInfinite()); // bool(true) // Get limited number of occurrences $next_30_days = $rrule->getOccurrences(30); echo count($next_30_days); // 30 // Safe iteration with manual break $count = 0; foreach ($rrule as $occurrence) { echo $occurrence->format('Y-m-d') . "\n"; $count++; if ($count >= 10) { break; // MUST break manually for infinite rules } } // Use date range instead $this_month = $rrule->getOccurrencesBetween('2023-01-01', '2023-01-31'); echo count($this_month); // 31 // Attempting to get all occurrences will throw exception try { $all = $rrule->getOccurrences(); // No limit on infinite rule } catch (\LogicException $e) { echo $e->getMessage(); // Cannot get all occurrences of an infinite recurrence rule. } ``` -------------------------------- ### Create RSet from RFC String - PHP Source: https://github.com/rlanvin/php-rrule/wiki/RSet Initializes an RSet object from a string formatted according to RFC 5545, which can include DTSTART, RRULE, EXRULE, EXDATE, and RDATE properties. If DTSTART is not present in the string, a default date can be provided as a second argument. ```php $rset = new RSet( "DTSTART;TZID=America/New_York:19970901T090000\n RRULE:FREQ=DAILY;COUNT=3\n EXRULE:FREQ=DAILY;INTERVAL=2;COUNT=1\n EXDATE;TZID=America/New_York:19970903T090000\n RDATE;TZID=America/New_York:19970904T090000" ); ``` -------------------------------- ### Create RRule Object from String Source: https://github.com/rlanvin/php-rrule/wiki/RRule Instantiate an RRule object using RFC-like syntax passed as a string. Supports multi-line strings with DTSTART and RRULE, single-line RRULE strings, or just the RRULE property value. DTSTART and RRULE must be separated by newline characters. Versions >= 1.5 allow specifying DTSTART via a second argument when not present in the string. Versions >= 1.3 throw InvalidArgumentException for invalid strings. Versions >= 1.5 offer `RRule::createFromRfcString()` for parsing. ```php new RRule('DTSTART;TZID=America/New_York:19970901T090000 RRULE:FREQ=DAILY;UNTIL=19971224T000000Z;WKST=SU;BYDAY=MO,WE,FR;BYMONTH=1'); new RRule('RRULE:FREQ=DAILY;UNTIL=19971224T000000Z;WKST=SU;BYDAY=MO,WE,FR;BYMONTH=1'); new RRule('FREQ=DAILY;UNTIL=19971224T000000Z;WKST=SU;BYDAY=MO,WE,FR;BYMONTH=1'); // Since version 1.5, specify DTSTART explicitly when not in string new RRule('FREQ=DAILY', new DateTime('1997-12-24')); // Using the factory method (versions >= 1.5) // RRule::createFromRfcString('...'); ``` -------------------------------- ### Human-Readable Output with Localization Source: https://context7.com/rlanvin/php-rrule/llms.txt Generate natural language descriptions of recurrence rules in multiple languages using the RRule class. This feature supports localization for various languages and allows customization of date formats and inclusion of start/end information. Dependencies include the RRule class and IntlDateFormatter. ```php use RRule\RRule; $rrule = new RRule([ 'FREQ' => 'WEEKLY', 'INTERVAL' => 2, 'BYDAY' => 'MO,WE,FR', 'DTSTART' => '1997-09-01 09:00:00', 'UNTIL' => '1997-12-24 00:00:00' ]); // English (default) echo $rrule->humanReadable(['locale' => 'en']) . "\n"; // every other week on Monday, Wednesday and Friday, starting from 9/1/97, until 12/24/97 // French echo $rrule->humanReadable(['locale' => 'fr']) . "\n"; // une semaine sur deux le lundi, mercredi et vendredi, à partir du 01/09/97, jusqu'au 24/12/97 // German echo $rrule->humanReadable(['locale' => 'de']) . "\n"; // jede 2. Woche am Montag, Mittwoch und Freitag, beginnend am 01.09.97, bis zum 24.12.97 // Custom date format with IntlDateFormatter echo $rrule->humanReadable([ 'locale' => 'en_US', 'date_format' => IntlDateFormatter::FULL ]) . "\n"; // every other week on Monday, Wednesday and Friday, starting from Monday, September 1, 1997, until Wednesday, December 24, 1997 // Without start/end information echo $rrule->humanReadable([ 'include_start' => false, 'include_until' => false ]) . "\n"; // every other week on Monday, Wednesday and Friday ``` -------------------------------- ### Create Rule from RFC String Source: https://context7.com/rlanvin/php-rrule/llms.txt Parse RFC 5545 formatted strings to create recurrence rules. This is useful for importing existing recurrence rule definitions. ```APIDOC ## Create Rule from RFC String ### Description Parse RFC 5545 formatted strings to create recurrence rules. This is useful for importing existing recurrence rule definitions. ### Method `__construct(string $rfcString, ?DateTimeInterface $dtstart = null)` or `__construct(array $options)` ### Parameters #### Request Body (String or Array) - **rfcString** (string) - Required - An RFC 5545 formatted string containing DTSTART and RRULE, or just the RRULE portion. - **dtstart** (DateTimeInterface) - Optional - A DateTime object to be used as the DTSTART if not provided in the rfcString. ### Request Example ```php use RRule\RRule; // From RFC-compliant string with DTSTART and RRULE $rrule = new RRule( "DTSTART;TZID=America/New_York:19970901T090000\n" . "RRULE:FREQ=DAILY;UNTIL=19971224T000000Z;WKST=SU;BYDAY=MO,WE,FR;BYMONTH=1" ); // Or from just the RRULE portion $rrule = new RRule('FREQ=DAILY;COUNT=10', new DateTime('1997-09-02')); ``` ### Response #### Success Response (Object) - **RRule Object** - An instance of the RRule class representing the parsed recurrence rule. #### Response Example ```php // Get all occurrences $occurrences = $rrule->getOccurrences(); foreach ($occurrences as $date) { echo $date->format('Y-m-d H:i:s') . "\n"; } // Export back to RFC string echo $rrule->rfcString(); // Output: DTSTART;TZID=America/New_York:19970901T090000 // RRULE:FREQ=DAILY;UNTIL=19971224T000000Z;WKST=SU;BYDAY=MO,WE,FR;BYMONTH=1 ``` ``` -------------------------------- ### Check if a specific datetime occurs within an RRule Source: https://github.com/rlanvin/php-rrule/wiki/RRuleInterface The `occursAt` method checks if a given datetime falls on an occurrence defined by the RRule. It accepts various input formats for the datetime, including strings parsable by `DateTime`, UNIX timestamps, or `DateTime` objects. This method only verifies the start of an event, not its duration. ```php $rrule = new RRule([ 'FREQ' => 'WEEKLY', 'INTERVAL' => 2, 'DTSTART' => '2016-01-01', ]); $rrule->occursAt('2016-01-01'); // true $rrule->occursAt('2016-01-07'); // false ```