### Generate Recurrences from a Specific Date in Ruby Source: https://github.com/square/ruby-rrule/blob/master/README.md Illustrates how to generate all recurrence instances starting from a specified date using the '#from' method, with an optional 'dtstart' override. ```ruby rrule = RRule::Rule.new('FREQ=DAILY;COUNT=3', dtstart: Time.new(2016, 1, 1)) rrule.all rrule.from(Time.new(2016, 1, 2)) ``` -------------------------------- ### Get Occurrences Starting From Date with #from - Ruby Source: https://context7.com/square/ruby-rrule/llms.txt Returns a specified number of recurrence instances starting from a given date. This method is useful for retrieving the next N occurrences after a particular point in time. It requires a `limit` parameter to specify how many occurrences to fetch. ```ruby rrule = RRule::Rule.new('FREQ=WEEKLY;BYDAY=MO,WE,FR', dtstart: Time.new(2024, 1, 1, 8, 0, 0), tzid: 'UTC') # Get next 5 occurrences starting from a specific date start_from = Time.new(2024, 2, 1) rrule.from(start_from, limit: 5) # => [2024-02-02 08:00:00 UTC, 2024-02-05 08:00:00 UTC, 2024-02-07 08:00:00 UTC, # 2024-02-09 08:00:00 UTC, 2024-02-12 08:00:00 UTC] ``` -------------------------------- ### Complex Yearly Recurrence Rule Example (Ruby) Source: https://context7.com/square/ruby-rrule/llms.txt This example demonstrates a complex yearly recurrence rule for an event that occurs every 4 years in November, on a Tuesday between the 2nd and 8th day of the month. It includes the start date and timezone for accurate recurrence generation. ```ruby rrule = RRule::Rule.new( 'FREQ=YEARLY;INTERVAL=4;BYMONTH=11;BYDAY=TU;BYMONTHDAY=2,3,4,5,6,7,8', dtstart: Time.new(1996, 11, 5, 0, 0, 0), tzid: 'America/New_York' ) rrule.between(Time.new(1996, 1, 1), Time.new(2024, 12, 31)) # => [1996-11-05, 2000-11-07, 2004-11-02, 2008-11-04, 2012-11-06, 2016-11-08, 2020-11-03, 2024-11-05] ``` -------------------------------- ### Create RRule::Rule Instance - Ruby Source: https://context7.com/square/ruby-rrule/llms.txt Creates an RRule::Rule instance by parsing an RRULE string. Accepts options for start date (dtstart), timezone (tzid), exception dates (exdate), and maximum year boundary. Supports basic and complex recurrence patterns, including those with intervals and by-* filters. ```ruby require 'rrule' # Basic usage - create a daily recurrence with 5 occurrences rrule = RRule::Rule.new('FREQ=DAILY;COUNT=5', dtstart: Time.new(2024, 1, 1, 9, 0, 0), tzid: 'America/New_York') # Alternative syntax using RRule.parse rrule = RRule.parse('FREQ=DAILY;COUNT=5', dtstart: Time.new(2024, 1, 1, 9, 0, 0), tzid: 'America/New_York') # Complex weekly rule - every 2 weeks on Tuesday and Thursday rrule = RRule::Rule.new( 'FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,TH;COUNT=8', dtstart: Time.new(2024, 1, 2, 10, 30, 0), tzid: 'America/Los_Angeles' ) rrule.all # => [2024-01-02 10:30:00 -0800, 2024-01-04 10:30:00 -0800, # 2024-01-16 10:30:00 -0800, 2024-01-18 10:30:00 -0800, ...] # With exception dates (EXDATE) rrule = RRule::Rule.new( 'FREQ=DAILY;COUNT=5', dtstart: Time.new(2024, 1, 1, 9, 0, 0), tzid: 'UTC', exdate: [Time.new(2024, 1, 2, 9, 0, 0), Time.new(2024, 1, 4, 9, 0, 0)] ) rrule.all # => [2024-01-01 09:00:00 UTC, 2024-01-03 09:00:00 UTC, 2024-01-05 09:00:00 UTC] ``` -------------------------------- ### Second-to-Last Weekday of Month Recurrence Rule (Ruby) Source: https://context7.com/square/ruby-rrule/llms.txt This example defines a recurrence rule for the second-to-last weekday (Monday to Friday) of each month. It uses BYSETPOS=-2 to specify the second-to-last occurrence within the set of weekdays for that month. ```ruby rrule = RRule::Rule.new( 'FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-2', dtstart: Time.new(2024, 1, 1), tzid: 'UTC' ) rrule.all(limit: 3) # => [2024-01-30, 2024-02-28, 2024-03-28] ``` -------------------------------- ### Get Original RRULE String with Ruby RRULE Source: https://context7.com/square/ruby-rrule/llms.txt Illustrates how to retrieve the original RRULE string representation of a rule object using the #to_s method. This is useful for serialization, storage, and recreating rule objects later. ```ruby require 'rrule' rrule_string = 'RRULE:FREQ=WEEKLY;INTERVAL=2;BYDAY=MO,WE,FR;COUNT=10' rrule = RRule::Rule.new(rrule_string, dtstart: Time.new(2024, 1, 1), tzid: 'UTC') rrule.to_s # => "RRULE:FREQ=WEEKLY;INTERVAL=2;BYDAY=MO,WE,FR;COUNT=10" # Store and recreate stored_rule = rrule.to_s stored_dtstart = rrule.dtstart stored_tz = rrule.tz recreated = RRule::Rule.new(stored_rule, dtstart: stored_dtstart, tzid: stored_tz) ``` -------------------------------- ### Monthly Friday the 13th Recurrence Rule (Ruby) Source: https://context7.com/square/ruby-rrule/llms.txt This example shows how to create a recurrence rule for events that occur monthly on the 13th day of the month, but only if that day falls on a Friday. It also includes a COUNT to limit the number of occurrences. ```ruby rrule = RRule::Rule.new('FREQ=MONTHLY;BYDAY=FR;BYMONTHDAY=13;COUNT=6', dtstart: Time.new(2024, 1, 1), tzid: 'UTC') rrule.all # => [2024-09-13, 2024-12-13, 2025-06-13, 2026-02-13, 2026-03-13, 2026-11-13] ``` -------------------------------- ### Generate Yearly Birthday Reminders with Ruby RRULE Source: https://context7.com/square/ruby-rrule/llms.txt Demonstrates how to create a yearly recurring rule for a birthday reminder using the RRule::Rule class. It specifies the frequency, month, and day, and then generates the next three occurrences after a given start date. ```ruby require 'rrule' # Yearly birthday reminder - next 3 occurrences after today birthday = RRule::Rule.new('FREQ=YEARLY;BYMONTH=7;BYMONTHDAY=15', dtstart: Time.new(1990, 7, 15), tzid: 'UTC') birthday.from(Time.new(2024, 1, 1), limit: 3) # => [2024-07-15 00:00:00 UTC, 2025-07-15 00:00:00 UTC, 2026-07-15 00:00:00 UTC] ``` -------------------------------- ### Get Occurrences in Date Range with #between - Ruby Source: https://context7.com/square/ruby-rrule/llms.txt Returns recurrence instances that fall within a specified date range (inclusive). This method is useful for displaying events in calendar views within a particular time window. An optional `limit` parameter can cap the number of results. ```ruby rrule = RRule::Rule.new('FREQ=DAILY;INTERVAL=2', dtstart: Time.new(2024, 1, 1, 9, 0, 0), tzid: 'UTC') # Get occurrences between two dates start_date = Time.new(2024, 1, 10, 0, 0, 0) end_date = Time.new(2024, 1, 20, 23, 59, 59) rrule.between(start_date, end_date) # => [2024-01-11 09:00:00 UTC, 2024-01-13 09:00:00 UTC, 2024-01-15 09:00:00 UTC, # 2024-01-17 09:00:00 UTC, 2024-01-19 09:00:00 UTC] # With a limit rrule.between(start_date, end_date, limit: 3) # => [2024-01-11 09:00:00 UTC, 2024-01-13 09:00:00 UTC, 2024-01-15 09:00:00 UTC] # Monthly meeting on second Monday - find occurrences in Q1 2024 rrule = RRule::Rule.new('FREQ=MONTHLY;BYDAY=2MO', dtstart: Time.new(2024, 1, 8, 10, 0, 0), tzid: 'America/New_York') rrule.between(Time.new(2024, 1, 1), Time.new(2024, 3, 31)) # => [2024-01-08 10:00:00 -0500, 2024-02-12 10:00:00 -0500, 2024-03-11 10:00:00 -0400] ``` -------------------------------- ### Create and Parse RRULE Strings in Ruby Source: https://github.com/square/ruby-rrule/blob/master/README.md Demonstrates how to create an RRule object from an RRULE string using both the Rule.new and RRule.parse methods. ```ruby rrule = RRule::Rule.new('FREQ=DAILY;COUNT=3') rrule = RRule.parse('FREQ=DAILY;COUNT=3') # alternate syntax ``` -------------------------------- ### Override DTSTART and Specify Timezone in Ruby Source: https://github.com/square/ruby-rrule/blob/master/README.md Explains how to override the default DTSTART and specify a timezone using the 'dtstart' and 'tzid' options for accurate recurrence evaluation. ```ruby rrule = RRule::Rule.new('FREQ=DAILY;COUNT=3', dtstart: Time.new(2016, 7, 1)) rrule.all rrule = RRule::Rule.new('FREQ=DAILY;COUNT=3', dtstart: Time.new(2016, 7, 1), tzid: 'America/Los_Angeles') ``` -------------------------------- ### Generate Recurrence Instances in Ruby Source: https://github.com/square/ruby-rrule/blob/master/README.md Shows how to generate all recurrence instances or instances within a specific date range using the 'all' and 'between' methods. ```ruby rrule.all rrule.between(Time.new(2016, 6, 23), Time.new(2016, 6, 24)) ``` -------------------------------- ### Limit Recurrence Instances in Ruby Source: https://github.com/square/ruby-rrule/blob/master/README.md Demonstrates how to limit the number of recurrence instances returned by the 'all' method using the 'limit' option. ```ruby rrule = RRule::Rule.new('FREQ=DAILY;COUNT=3') rrule.all(limit: 2) ``` -------------------------------- ### Define Exception Dates (EXDATEs) in Ruby Source: https://github.com/square/ruby-rrule/blob/master/README.md Shows how to define exception dates for a recurrence rule by passing an array of dates to the 'exdate' option. ```ruby rrule = RRule::Rule.new('FREQ=DAILY;COUNT=3', dtstart: Time.new(2016, 7, 1), exdate: [DateTime.parse('2016-07-02 00:00:00 -0700')]) rrule.all ``` -------------------------------- ### Add rrule Gem to Gemfile Source: https://github.com/square/ruby-rrule/blob/master/README.md Instructions on how to add the rrule gem to your project's Gemfile for dependency management. ```ruby gem 'rrule' ``` -------------------------------- ### Human-Readable Description of RRULEs with Ruby RRULE Source: https://context7.com/square/ruby-rrule/llms.txt Shows how to convert an RRULE string into a human-readable description using the #humanize method. This is useful for displaying recurrence patterns to end users in a friendly format, covering daily, weekly, bi-weekly, monthly, and yearly patterns. ```ruby require 'rrule' # Daily recurrence rrule = RRule::Rule.new('FREQ=DAILY;INTERVAL=1', dtstart: Time.new(2024, 1, 1), tzid: 'UTC') rrule.humanize # => "every day" # Weekly on specific days rrule = RRule::Rule.new('FREQ=WEEKLY;INTERVAL=1;BYDAY=TU,TH', dtstart: Time.new(2024, 1, 1), tzid: 'UTC') rrule.humanize # => "every week on Tuesday, Thursday" # Bi-weekly rrule = RRule::Rule.new('FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,TH', dtstart: Time.new(2024, 1, 1), tzid: 'UTC') rrule.humanize # => "every 2 weeks on Tuesday, Thursday" # Monthly on last Friday with count rrule = RRule::Rule.new('FREQ=MONTHLY;BYDAY=-1FR;COUNT=7', dtstart: Time.new(2024, 1, 1), tzid: 'UTC') rrule.humanize # => "every month on the last Friday for 7 times" # Yearly on specific date rrule = RRule::Rule.new('FREQ=YEARLY;BYMONTH=1;BYMONTHDAY=1', dtstart: Time.new(2024, 1, 1), tzid: 'UTC') rrule.humanize # => "every year on January 1st" ``` -------------------------------- ### Sequential Iteration and Enumerable Methods with Ruby RRULE Source: https://context7.com/square/ruby-rrule/llms.txt Explains how to iterate through occurrences sequentially using the #next method and leverage Enumerable methods like #take. This is useful for lazy evaluation when processing occurrences one at a time. The Rule class includes Enumerable, allowing standard iteration methods. ```ruby require 'rrule' rrule = RRule::Rule.new('FREQ=DAILY;COUNT=10', dtstart: Time.new(2024, 1, 1, 9, 0, 0), tzid: 'UTC') # Get occurrences sequentially rrule.next # => 2024-01-01 09:00:00 UTC rrule.next # => 2024-01-02 09:00:00 UTC rrule.next # => 2024-01-03 09:00:00 UTC # Use Enumerable methods rrule = RRule::Rule.new('FREQ=DAILY;COUNT=100', dtstart: Time.new(2024, 1, 1, 9, 0, 0), tzid: 'UTC') rrule.take(5) # => [2024-01-01 09:00:00 UTC, 2024-01-02 09:00:00 UTC, 2024-01-03 09:00:00 UTC, # 2024-01-04 09:00:00 UTC, 2024-01-05 09:00:00 UTC] # Iterate with a block rrule = RRule::Rule.new('FREQ=DAILY;COUNT=3', dtstart: Time.new(2024, 1, 1, 9, 0, 0), tzid: 'UTC') rrule.each { |occurrence| puts occurrence.strftime('%Y-%m-%d %H:%M') } # 2024-01-01 09:00 # 2024-01-02 09:00 # 2024-01-03 09:00 ``` -------------------------------- ### Generate All Occurrences with #all - Ruby Source: https://context7.com/square/ruby-rrule/llms.txt Returns an array of all recurrence instances based on the rule. For infinite recurrences, the `limit` parameter can be used to prevent infinite loops. This method is suitable when the complete set of occurrences is needed upfront. ```ruby rrule = RRule::Rule.new('FREQ=DAILY;COUNT=10', dtstart: Time.new(2024, 1, 1, 9, 0, 0), tzid: 'UTC') # Get all 10 occurrences rrule.all # => [2024-01-01 09:00:00 UTC, 2024-01-02 09:00:00 UTC, ..., 2024-01-10 09:00:00 UTC] # Limit results for infinite recurrences infinite_rule = RRule::Rule.new('FREQ=DAILY', dtstart: Time.new(2024, 1, 1, 9, 0, 0), tzid: 'UTC') infinite_rule.all(limit: 5) # => [2024-01-01 09:00:00 UTC, 2024-01-02 09:00:00 UTC, 2024-01-03 09:00:00 UTC, # 2024-01-04 09:00:00 UTC, 2024-01-05 09:00:00 UTC] # Monthly on the first Friday rrule = RRule::Rule.new('FREQ=MONTHLY;BYDAY=1FR;COUNT=6', dtstart: Time.new(2024, 1, 5, 14, 0, 0), tzid: 'America/New_York') rrule.all # => [2024-01-05 14:00:00 -0500, 2024-02-02 14:00:00 -0500, 2024-03-01 14:00:00 -0500, # 2024-04-05 14:00:00 -0400, 2024-05-03 14:00:00 -0400, 2024-06-07 14:00:00 -0400] ``` -------------------------------- ### Check if Recurrence Has an End with Ruby RRULE Source: https://context7.com/square/ruby-rrule/llms.txt Demonstrates how to use the #is_finite? method to check if a recurrence rule has a defined end, either through COUNT or UNTIL. It also provides a safe pattern for handling both finite and infinite recurrences when retrieving occurrences. ```ruby require 'rrule' # Finite recurrence with COUNT finite = RRule::Rule.new('FREQ=DAILY;COUNT=10', dtstart: Time.new(2024, 1, 1), tzid: 'UTC') finite.is_finite? # => true # Finite recurrence with UNTIL finite = RRule::Rule.new('FREQ=DAILY;UNTIL=20240131T000000Z', dtstart: Time.new(2024, 1, 1), tzid: 'UTC') finite.is_finite? # => true # Infinite recurrence infinite = RRule::Rule.new('FREQ=DAILY', dtstart: Time.new(2024, 1, 1), tzid: 'UTC') infinite.is_finite? # => false # Safe pattern for handling both cases def get_occurrences(rrule, max_limit: 100) if rrule.is_finite? rrule.all else rrule.all(limit: max_limit) end end ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.