### Install rrule.js with NPM Source: https://github.com/jkbrzt/rrule/blob/master/README.md Install the rrule.js library using NPM for server-side projects. ```bash $ npm install rrule ``` -------------------------------- ### Installing Dependencies Source: https://github.com/jkbrzt/rrule/blob/master/README.md To set up the development environment for rrule.js, you need to install the project dependencies using yarn. ```bash $ yarn ``` -------------------------------- ### DTSTART Format Examples Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/04-string-parsing.md Shows the basic format for DTSTART with and without a timezone. ```text DTSTART:YYYYMMDDTHHMMSSZ ``` ```text DTSTART;TZID=timezone:YYYYMMDDTHHMMSS ``` -------------------------------- ### Set and Get dtstart for RRuleSet Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/02-rruleset-class.md Demonstrates how to set an explicit start date for an RRuleSet and retrieve it later. The dtstart method can be used for both setting and getting the start date. ```typescript const set = new RRuleSet() // Set explicit start date set.dtstart(datetime(2023, 1, 1)) // Retrieve it later const start = set.dtstart() ``` -------------------------------- ### dtstart() Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/02-rruleset-class.md Gets or sets the start date for the entire RRuleSet. When used as a getter, it returns the `dtstart` from the first inclusive rule if not explicitly set. ```APIDOC ## dtstart() ### Description Gets or sets the start date for the entire RRuleSet. When used as a getter without arguments, returns the `dtstart` from the first inclusive rule if not explicitly set. ### Method `dtstart(date?: Date | null): Date | null | undefined` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **date** (`Date | null`) - Optional - Set the start date for the set. ### Returns The current `dtstart` (getter mode) or `undefined` if not set. ### Example ```typescript const set = new RRuleSet() // Set explicit start date set.dtstart(datetime(2023, 1, 1)) // Retrieve it later const start = set.dtstart() ``` ``` -------------------------------- ### Install rrule.js with Yarn Source: https://github.com/jkbrzt/rrule/blob/master/README.md Install the rrule.js library using Yarn for client-side or server-side projects. ```bash $ yarn add rrule ``` -------------------------------- ### Set Week Start Day Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/07-configuration.md Configure the start day of the week using `wkst`. Defaults to Monday (ISO 8601). Accepts Weekday instances, numbers (0-6), or strings ('MO'-'SU'). Affects weekly and monthly/yearly byweekday calculations. ```typescript // ISO 8601 week (Monday start, default) new RRule({ freq: RRule.WEEKLY, byweekday: [RRule.MO, RRule.FR] // Weeks start on Monday }) // US convention (Sunday start) new RRule({ freq: RRule.WEEKLY, wkst: RRule.SU, byweekday: [RRule.MO, RRule.FR] // Weeks start on Sunday }) ``` -------------------------------- ### RFC String Format: With Start Date Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/API-SUMMARY.md Specifies a start date for a daily recurrence rule. ```text DTSTART:20230601T000000Z RRULE:FREQ=DAILY;COUNT=7 ``` -------------------------------- ### RDATE Format Example Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/04-string-parsing.md Demonstrates the format for RDATE, which specifies explicit inclusion dates separated by commas. ```text RDATE:datetime,datetime,... ``` -------------------------------- ### Supported Frequency Formats Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/05-natural-language.md These examples demonstrate basic frequency patterns supported by RRule.parseText(). ```plaintext every day every week every month every year every hour every minute every second ``` -------------------------------- ### Set Start Date and Time with datetime Helper Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/07-configuration.md Define the start date and time for recurrence. The `datetime` helper is recommended to prevent timezone issues. Missing time components default to midnight. ```typescript import { datetime } from 'rrule' new RRule({ freq: RRule.DAILY, dtstart: datetime(2023, 1, 1, 9, 0) // 9 AM }) // All occurrences will be at 9 AM ``` -------------------------------- ### EXDATE Format Example Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/04-string-parsing.md Illustrates the format for EXDATE, which specifies explicit exclusion dates separated by commas. ```text EXDATE:datetime,datetime,... ``` -------------------------------- ### RRULE Format Example Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/04-string-parsing.md Illustrates the basic structure of an RRULE string, including the required FREQ and optional parameters. ```text RRULE:FREQ=frequency;parameters ``` -------------------------------- ### RRule Constructor Example Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/01-rrule-class.md Demonstrates creating an RRule instance to generate weekly events on Mondays and Fridays until the end of 2012. Requires importing RRule and datetime. ```typescript import { RRule, datetime } from 'rrule' // Every week on Monday and Friday until end of 2012 const rule = new RRule({ freq: RRule.WEEKLY, interval: 1, byweekday: [RRule.MO, RRule.FR], dtstart: datetime(2012, 1, 1, 10, 30), until: datetime(2012, 12, 31) }) // Generate all dates const dates = rule.all() ``` -------------------------------- ### Parse Simple Daily Recurrence Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/04-string-parsing.md Parses a simple daily recurrence rule for a fixed number of occurrences. The first example uses the current date as DTSTART, while the second specifies an explicit start date. ```typescript const rule = rrulestr('FREQ=DAILY;COUNT=7') // Every day for 7 days, starting from current date ``` ```typescript const rule2 = rrulestr( 'DTSTART:20230601T000000Z\nRRULE:FREQ=DAILY;COUNT=7' ) // Every day for 7 days, starting June 1, 2023 ``` -------------------------------- ### Natural Language Format: Simple Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/API-SUMMARY.md Examples of simple recurrence rules expressed in natural language. ```text every day for 10 times every week on Monday, Friday every month on the 15th ``` -------------------------------- ### RRule Option Inference Examples Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/07-configuration.md Illustrates how RRule infers certain options like month, day, or weekday from the `dtstart` and `freq` when not explicitly provided. ```typescript // YEARLY without by* options -> uses month and day of dtstart new RRule({ freq: RRule.YEARLY, dtstart: datetime(2023, 3, 15) }) // Generates March 15 every year ``` ```typescript // MONTHLY without by* options -> uses day of dtstart new RRule({ freq: RRule.MONTHLY, dtstart: datetime(2023, 1, 20) }) // Generates 20th of every month ``` ```typescript // WEEKLY without byweekday -> uses weekday of dtstart new RRule({ freq: RRule.WEEKLY, dtstart: datetime(2023, 1, 2) // Monday }) // Generates every Monday ``` -------------------------------- ### Termination Conditions for Recurrence Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/05-natural-language.md Examples of how to specify termination conditions for recurrence rules, either by a count or a specific date. ```plaintext for 10 times for 30 times until December 31, 2024 until December 31 ``` -------------------------------- ### EXRULE Format Example Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/04-string-parsing.md Shows the format for EXRULE, used for exclusion rules. Note that this is deprecated in RFC 5545 but still supported. ```text EXRULE:FREQ=frequency;parameters ``` -------------------------------- ### Configure the start of the week for weekly rules Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/06-helper-functions.md Set the `wkst` option to define the first day of the week for weekly recurrence rules. This can be set to `RRule.SU` for Sunday (US convention) or `RRule.MO` for Monday (ISO 8601, default). ```typescript import { RRule, datetime } from 'rrule' // Week starts on Sunday (US convention) const rule = new RRule({ freq: RRule.WEEKLY, wkst: RRule.SU, byweekday: [RRule.MO, RRule.WE, RRule.FR], dtstart: datetime(2023, 1, 1), count: 8 }) // Week starts on Monday (ISO 8601, default) const ruleISO = new RRule({ freq: RRule.WEEKLY, wkst: RRule.MO, // Default, can be omitted byweekday: [RRule.MO, RRule.WE, RRule.FR], dtstart: datetime(2023, 1, 1), count: 8 }) ``` -------------------------------- ### Define Project Milestones with RRuleSet Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/08-quick-start-examples.md Create a project milestone schedule using RRuleSet. This example includes monthly check-ins, quarterly reviews, bi-weekly sprint planning, and specific milestone dates. ```typescript import { RRuleSet, RRule, datetime } from 'rrule' const milestones = new RRuleSet() // Monthly check-ins on 1st milestones.rrule(new RRule({ freq: RRule.MONTHLY, bymonthday: 1, count: 12, dtstart: datetime(2023, 1, 1, 10, 0) })) // Quarterly reviews (1st, Apr 1, Jul 1, Oct 1) milestones.rrule(new RRule({ freq: RRule.YEARLY, bymonth: [1, 4, 7, 10], bymonthday: 1, count: 4, dtstart: datetime(2023, 1, 1, 14, 0) })) // Sprint planning every other Monday milestones.rrule(new RRule({ freq: RRule.WEEKLY, interval: 2, byweekday: RRule.MO, count: 26, byhour: 9, dtstart: datetime(2023, 1, 2, 9, 0) })) // Special milestone dates milestones.rdate(datetime(2023, 3, 15)) // Design review milestones.rdate(datetime(2023, 9, 1)) // Beta launch const allMilestones = milestones.all() ``` -------------------------------- ### Create and Use an RRule Object Source: https://github.com/jkbrzt/rrule/blob/master/README.md Demonstrates creating an RRule object with specific recurrence properties and retrieving all occurrences or a date range. The output shows example dates and a string representation of the rule. ```es6 import { datetime, RRule, RRuleSet, rrulestr } from 'rrule' // Create a rule: const rule = new RRule({ freq: RRule.WEEKLY, interval: 5, byweekday: [RRule.MO, RRule.FR], dtstart: datetime(2012, 2, 1, 10, 30), until: datetime(2012, 12, 31) }) // Get all occurrence dates (Date instances): rule.all() [ '2012-02-03T10:30:00.000Z', '2012-03-05T10:30:00.000Z', '2012-03-09T10:30:00.000Z', '2012-04-09T10:30:00.000Z', '2012-04-13T10:30:00.000Z', '2012-05-14T10:30:00.000Z', '2012-05-18T10:30:00.000Z', /* … */] // Get a slice: rule.between(datetime(2012, 8, 1), datetime(2012, 9, 1)) ['2012-08-27T10:30:00.000Z', '2012-08-31T10:30:00.000Z'] // Get an iCalendar RRULE string representation: // The output can be used with RRule.fromString(). rule.toString() "DTSTART:20120201T093000Z\nRRULE:FREQ=WEEKLY;INTERVAL=5;UNTIL=20130130T230000Z;BYDAY=MO,FR" // Get a human-friendly text representation: // The output can be used with RRule.fromText(). rule.toText() "every 5 weeks on Monday, Friday until January 31, 2013" ``` -------------------------------- ### Create a Daily Rule Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/README.md Create a daily rule that occurs 10 times starting from January 1, 2023. Always use the `datetime()` helper for UTC dates. ```typescript import { RRule, datetime } from 'rrule' const rule = new RRule({ freq: RRule.DAILY, count: 10, dtstart: datetime(2023, 1, 1) }) ``` -------------------------------- ### Weekday nth() Method Examples Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/03-types.md Demonstrates using the nth() method to find the last Friday of a month or the second Monday of a month. ```typescript // Last Friday of month const lastFriday = RRule.FR.nth(-1) // 2nd Monday of month const secondMonday = RRule.MO.nth(2) ``` -------------------------------- ### Round-Trip Conversion Example Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/05-natural-language.md Illustrates the round-trip conversion process from natural language text to an RRule object and back to text. Note that the generated text may differ slightly from the original due to formatting variations. ```typescript import { RRule, datetime } from 'rrule' // Start with text const text1 = 'every week on Monday and Friday for 12 times' const rule1 = RRule.fromText(text1) // Convert back to text const text2 = rule1.toText() // May differ slightly but represents same recurrence console.log(text1 === text2) // Usually false due to formatting console.log(rule1.all().length === 12) // true ``` -------------------------------- ### Create a Daily Rule Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/08-quick-start-examples.md Generates a daily recurrence rule for a specified count of days starting from a given date. Useful for simple, fixed-duration daily events. ```typescript import { RRule, datetime } from 'rrule' // Daily rule for 7 days const rule = new RRule({ freq: RRule.DAILY, count: 7, dtstart: datetime(2023, 6, 1) }) // Get all dates const dates = rule.all() console.log(dates) // [2023-06-01, 2023-06-02, ..., 2023-06-07] ``` -------------------------------- ### RRule between() Method Examples Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/01-rrule-class.md Fetches occurrences within a specified date range. The `inc` parameter controls whether the boundary dates are included in the result. ```typescript const rule = new RRule({ freq: RRule.DAILY, dtstart: datetime(2023, 1, 1), until: datetime(2023, 12, 31) }) // Get dates in March, excluding boundary dates const marchDates = rule.between( datetime(2023, 3, 1), datetime(2023, 3, 31), false ) // Get dates in March, including boundary dates if they match const marchInclusive = rule.between( datetime(2023, 3, 1), datetime(2023, 3, 31), true ) ``` -------------------------------- ### Configure Yearly by Week Number Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/07-configuration.md Use `byweekno` to specify ISO 8601 week numbers (1-53) for yearly recurrences. This option is valid only with `YEARLY` frequency. Weeks start on Monday by default. ```typescript new RRule({ freq: RRule.YEARLY, byweekno: [1, 26] }) ``` ```typescript new RRule({ freq: RRule.YEARLY, byweekno: 1 }) ``` -------------------------------- ### RRule: Weekly recurrence across DST transition with timezone Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/07-configuration.md Set up weekly recurrences and specify the IANA timezone identifier using `tzid` to correctly handle Daylight Saving Time transitions. This example schedules a weekly meeting on Mondays. ```typescript new RRule({ freq: RRule.WEEKLY, byweekday: RRule.MO, count: 10, dtstart: datetime(2023, 3, 1, 14, 0), tzid: 'America/New_York' }) ``` -------------------------------- ### Get or Set Start Date in RRuleSet Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/API-SUMMARY.md Retrieves the start date of the RRuleSet, or sets it if a Date object is provided. If no date is provided, it returns the current start date or undefined. ```typescript dtstart(date?) ``` -------------------------------- ### Complex Scheduling with Multiple Rules and Exclusions Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/02-rruleset-class.md Constructs a complex schedule by combining recurring rules, specific dates, and exclusions. This example demonstrates monthly recurrences on the 15th and last Friday, with one-time events and excluded dates. ```typescript const set = new RRuleSet() set.dtstart(datetime(2023, 1, 1)) // Recurring monthly on the 15th set.rrule(new RRule({ freq: RRule.MONTHLY, count: 12, dtstart: datetime(2023, 1, 15) })) // Recurring monthly on the last Friday set.rrule(new RRule({ freq: RRule.MONTHLY, count: 12, dtstart: datetime(2023, 1, 27), byweekday: RRule.FR.nth(-1) })) // One-time events set.rdate(datetime(2023, 3, 20)) set.rdate(datetime(2023, 9, 21)) // Exclude specific meetings set.exdate(datetime(2023, 7, 15)) set.exdate(datetime(2023, 12, 25)) const schedule = set.all() ``` -------------------------------- ### Building for Distribution Source: https://github.com/jkbrzt/rrule/blob/master/README.md This command builds the project files for distribution, typically generating optimized JavaScript bundles. ```bash $ yarn build ``` -------------------------------- ### Get the day number within the year Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/06-helper-functions.md Use `getYearDay` to find the day's position within a year, starting from 1 for January 1st. This function correctly handles leap years. ```typescript import { getYearDay } from 'rrule/dateutil' console.log(getYearDay(datetime(2023, 1, 1))) // 1 (Jan 1) console.log(getYearDay(datetime(2023, 12, 31))) // 365 (Dec 31) console.log(getYearDay(datetime(2000, 2, 29))) // 60 (Feb 29 in leap year) ``` -------------------------------- ### Configure Monthly by Month Day Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/07-configuration.md Use `bymonthday` to specify the day(s) of the month for monthly recurrences. Accepts positive (1-31) or negative (-1 to -31) values for days from the start or end of the month, respectively. Invalid days for a given month are skipped. ```typescript new RRule({ freq: RRule.MONTHLY, bymonthday: 15 }) ``` ```typescript new RRule({ freq: RRule.MONTHLY, bymonthday: -1 }) ``` ```typescript new RRule({ freq: RRule.MONTHLY, bymonthday: [1, 15] }) ``` ```typescript new RRule({ freq: RRule.MONTHLY, bymonthday: [1, -1] }) ``` -------------------------------- ### Create and Use an RRuleSet Object Source: https://github.com/jkbrzt/rrule/blob/master/README.md Demonstrates building an RRuleSet by adding recurrence rules, specific dates, and exclusions. It shows how to retrieve all occurrences, a date range, and string representations. ```js const rruleSet = new RRuleSet() // Add a rrule to rruleSet rruleSet.rrule( new RRule({ freq: RRule.MONTHLY, count: 5, dtstart: datetime(2012, 2, 1, 10, 30), }) ) // Add a date to rruleSet rruleSet.rdate(datetime(2012, 7, 1, 10, 30)) // Add another date to rruleSet rruleSet.rdate(datetime(2012, 7, 2, 10, 30)) // Add a exclusion rrule to rruleSet rruleSet.exrule( new RRule({ freq: RRule.MONTHLY, count: 2, dtstart: datetime(2012, 3, 1, 10, 30), }) ) // Add a exclusion date to rruleSet rruleSet.exdate(datetime(2012, 5, 1, 10, 30)) // Get all occurrence dates (Date instances): rruleSet.all()[ ('2012-02-01T10:30:00.000Z', '2012-05-01T10:30:00.000Z', '2012-07-01T10:30:00.000Z', '2012-07-02T10:30:00.000Z') ] // Get a slice: rruleSet.between(datetime(2012, 2, 1), datetime(2012, 6, 2))[ ('2012-05-01T10:30:00.000Z', '2012-07-01T10:30:00.000Z') ] // To string rruleSet.valueOf()[ ('DTSTART:20120201T023000Z', 'RRULE:FREQ=MONTHLY;COUNT=5', 'RDATE:20120701T023000Z,20120702T023000Z', 'EXRULE:FREQ=MONTHLY;COUNT=2', 'EXDATE:20120601T023000Z') ] // To string rruleSet.toString() ;('["DTSTART:20120201T023000Z","RRULE:FREQ=MONTHLY;COUNT=5","RDATE:20120701T023000Z,20120702T023000Z","EXRULE:FREQ=MONTHLY;COUNT=2","EXDATE:20120601T023000Z"]') ``` -------------------------------- ### Get Inclusive Rules from RRuleSet Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/API-SUMMARY.md Retrieves all inclusive RRule objects currently added to the RRuleSet. ```typescript rrules() ``` -------------------------------- ### Query with Iterator Control Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/API-SUMMARY.md Allows controlling the iteration of occurrences, for example, by limiting the number of results. ```typescript // With iterator control rule.all((date, index) => index < 10) ``` -------------------------------- ### Natural Language Format: Complex Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/API-SUMMARY.md Examples of more complex recurrence rules expressed in natural language. ```text every 2 weeks on Monday and Friday for 26 times every month on the last Friday for 12 times every year in January ``` -------------------------------- ### Configuration Options Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/README.md Reference for all 22 configuration options available for rrule.js. ```APIDOC ## Configuration Options ### Description Reference for all 22 configuration options available for rrule.js, detailing their type, default value, constraints, and examples. ### Options - `freq`: Frequency of the recurrence (e.g., 'YEARLY', 'MONTHLY'). - `dtstart`: The start date of the recurrence. - `until`: The end date of the recurrence. - `count`: The number of occurrences. - `interval`: The interval between occurrences. - `wkst`: The start day of the week. - `byyearday`: Specifies the year day(s). - `byweekno`: Specifies the week number(s). - `byweekday`: Specifies the weekday(s). - `bymonthday`: Specifies the month day(s). - `byhour`: Specifies the hour(s). - `byminute`: Specifies the minute(s). - `bysecond`: Specifies the second(s). - `m`: - `tzid`: Timezone ID. - `rrule`: - `rdate`: - `exrule`: - `exdate`: - `cache`: - `no_dtstart`: - `dtend`: ``` -------------------------------- ### Initialize RRuleSet and Add Rules Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/02-rruleset-class.md Demonstrates how to create an RRuleSet instance and add inclusive recurrence rules, specific dates, and exclusion dates. This is useful for defining complex event schedules. ```typescript import { RRule, RRuleSet, datetime } from 'rrule' const rruleSet = new RRuleSet() // Add multiple recurrence rules rruleSet.rrule(new RRule({ freq: RRule.WEEKLY, count: 5, dtstart: datetime(2023, 1, 2), // Monday byweekday: RRule.MO })) // Add specific dates rruleSet.rdate(datetime(2023, 1, 20)) // Exclude specific dates rruleSet.exdate(datetime(2023, 1, 9)) // Get results const dates = rruleSet.all() ``` -------------------------------- ### Date Creation: Recommended datetime() Helper Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/API-SUMMARY.md Uses the recommended `datetime()` helper function for creating date objects to avoid timezone issues. Ensure `datetime` is imported from `rrule`. ```typescript // RECOMMENDED: Use datetime() helper import { datetime } from 'rrule' const d = datetime(2023, 6, 15, 14, 30) ``` -------------------------------- ### Get first occurrence after a date from RRuleSet Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/02-rruleset-class.md Returns the first occurrence at or after the given date. This method is inherited from RRule. ```typescript after(dt: Date, inc?: boolean): Date | null ``` -------------------------------- ### Get last occurrence before a date from RRuleSet Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/02-rruleset-class.md Returns the last occurrence at or before the given date. This method is inherited from RRule. ```typescript before(dt: Date, inc?: boolean): Date | null ``` -------------------------------- ### RRuleSet Instance Methods Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/INDEX.md Explains the instance methods for RRuleSet objects, used for managing complex recurrence rules with inclusions and exclusions. ```APIDOC ## RRuleSet Instance Methods ### `rrule(rule)` **Purpose**: Add an inclusive recurrence rule to the rule set. * `rule` (RRule): The rule to add. ### `rdate(date)` **Purpose**: Add an inclusive date to the rule set. * `date` (Date): The date to add. ### `exrule(rule)` **Purpose**: Add an exclusive recurrence rule to the rule set. * `rule` (RRule): The rule to add. ### `exdate(date)` **Purpose**: Add an exclusive date to the rule set. * `date` (Date): The date to add. ### `rrules()` **Returns**: `RRule[]` **Purpose**: Get all inclusive rules from the rule set. ### `rdates()` **Returns**: `Date[]` **Purpose**: Get all inclusive dates from the rule set. ### `exrules()` **Returns**: `RRule[]` **Purpose**: Get all exclusive rules from the rule set. ### `exdates()` **Returns**: `Date[]` **Purpose**: Get all exclusive dates from the rule set. ### `dtstart(date?)` **Returns**: `Date | undefined` **Purpose**: Get or set the start date for the rule set. * `date` (Date, optional): The start date to set. ### `tzid(tz?)` **Returns**: `string | undefined` **Purpose**: Get or set the timezone ID for the rule set. * `tz` (string, optional): The timezone ID to set. ### `valueOf()` **Returns**: `string[]` **Purpose**: Get the RFC components of the rule set. ### `toString()` **Returns**: `string` **Purpose**: Serialize the rule set to an RFC-compliant string. ### `clone()` **Returns**: `RRuleSet` **Purpose**: Create a deep copy of the RRuleSet instance. ``` -------------------------------- ### Weekday Class Methods Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/03-types.md Provides details on the methods available for the Weekday class, including constructor, static factory, and instance methods for manipulation and comparison. ```APIDOC ## Class: Weekday Represents a weekday with optional position qualifier (nth occurrence). ### Constructor ```typescript new Weekday(weekday: number, n?: number) ``` **Parameters**: - `weekday` (number): Weekday 0-6. (0=Monday, 6=Sunday) - `n` (number, optional): Position qualifier. Throws if `n === 0`. **Throws**: `Error` if `n === 0`. ### Static Method: fromStr ```typescript static fromStr(str: WeekdayStr): Weekday ``` Creates a `Weekday` instance from a `WeekdayStr` literal. ### Instance Method: nth ```typescript nth(n: number): Weekday ``` Returns a new `Weekday` with the specified position qualifier. Returns `this` if already set to the same position. **Parameters**: - `n` (number): Position (1-52 for forward, -1 to -53 for backward). Cannot be 0. **Returns**: `Weekday` instance. **Example**: ```typescript // Last Friday of month const lastFriday = RRule.FR.nth(-1) // 2nd Monday of month const secondMonday = RRule.MO.nth(2) ``` ### Instance Method: equals ```typescript equals(other: Weekday): boolean ``` Checks equality of both weekday and position qualifier. ### Instance Method: toString ```typescript tostring(): string ``` Formats as RFC string: 'MO' (no position) or '+1MO', '-1MO' (with position). ### Instance Method: getJsWeekday ```typescript getJsWeekday(): number ``` Converts to JavaScript Date weekday convention (0=Sunday, 1=Monday...6=Saturday). **Returns**: Number 0-6. ``` -------------------------------- ### Parse RRULE String with Options Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/04-string-parsing.md Demonstrates parsing an RRULE string with custom options, including providing a default dtstart and enabling caching. Also shows RFC-compatible parsing. ```typescript // Provide default dtstart if not in string const rule = rrulestr( 'FREQ=MONTHLY;COUNT=12', { dtstart: new Date(2023, 0, 1), // Jan 1, 2023 cache: true } ) // RFC-compatible parsing const ruleSet = rrulestr( `DTSTART:20230101T000000Z RRULE:FREQ=DAILY;COUNT=5`, { compatible: true } ) // dtstart is included as first date ``` -------------------------------- ### Get RFC Components from RRuleSet Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/API-SUMMARY.md Returns a string array representing the RFC components of the RRuleSet, useful for serialization or debugging. ```typescript valueOf() ``` -------------------------------- ### RRule Constructor Source: https://github.com/jkbrzt/rrule/blob/master/README.md Initializes a new RRule object with specified options. The `freq` option is required, and other options correspond to RFC 5545 properties. ```APIDOC ## `RRule` Constructor ```javascript new RRule(options[, noCache=false]) ``` The `options` argument mostly corresponds to the properties defined for `RRULE` in the iCalendar RFC. Only `freq` is required. ### Parameters #### Options - **freq** (enum) - Required - One of the following constants: `RRule.YEARLY`, `RRule.MONTHLY`, `RRule.WEEKLY`, `RRule.DAILY`, `RRule.HOURLY`, `RRule.MINUTELY`, `RRule.SECONDLY`. - **dtstart** (Date) - The recurrence start. If not given, `new Date()` will be used instead. ``` -------------------------------- ### tzid() Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/02-rruleset-class.md Gets or sets the timezone identifier for the entire RRuleSet. When not explicitly set, it returns the `tzid` from the first inclusive rule. ```APIDOC ## tzid() ### Description Gets or sets the timezone identifier for the entire RRuleSet. When not explicitly set, returns the `tzid` from the first inclusive rule. ### Method `tzid(tz?: string): string | undefined` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **tz** (`string`) - Optional - IANA timezone identifier (e.g., 'America/New_York'). ### Returns The current timezone ID (getter mode) or `undefined`. ### Example ```typescript const set = new RRuleSet() // Set timezone set.tzid('America/Denver') // Retrieve it console.log(set.tzid()) // 'America/Denver' // Add rules that will use this timezone set.rrule(new RRule({ freq: RRule.DAILY, count: 5, dtstart: datetime(2023, 6, 1, 9, 0) })) ``` ``` -------------------------------- ### RRule after() Method Examples Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/01-rrule-class.md Identifies the first occurrence after a specified date. If `inc` is true, the date itself is considered if it matches the rule. ```typescript const rule = new RRule({ freq: RRule.WEEKLY, byweekday: RRule.FR, dtstart: datetime(2023, 1, 1), count: 52 }) // Next Friday after today const nextFriday = rule.after(new Date()) // Next Friday on or after June 1, 2023 const fridayFrom = rule.after(datetime(2023, 6, 1), true) ``` -------------------------------- ### Get exclusive dates from RRuleSet Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/02-rruleset-class.md Returns a copy of all exclusive dates that have been added to the set. The dates are returned as an array of Date objects. ```typescript exdates(): Date[] ``` -------------------------------- ### Create, Convert, and Display Recurrence Rule Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/INDEX.md Shows how to create a recurrence rule with specific options, convert it to a human-readable text format, and display it. ```typescript import { RRule, datetime } from 'rrule' // 1. Create with options const rule = new RRule({ freq: RRule.WEEKLY, byweekday: [RRule.MO, RRule.FR], count: 10, dtstart: datetime(2023, 1, 2) }) // 2. Convert to text const text = rule.toText() // 3. Display or store console.log(text) // "every week on Monday, Friday for 10 times" ``` -------------------------------- ### Get inclusive dates from RRuleSet Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/02-rruleset-class.md Returns a copy of all inclusive dates that have been added to the set. The dates are returned as an array of Date objects. ```typescript rdates(): Date[] ``` ```typescript const set = new RRuleSet() set.rdate(datetime(2023, 6, 15)) set.rdate(datetime(2023, 6, 20)) const dates = set.rdates() console.log(dates.length) // 2 ``` -------------------------------- ### Get exclusive RRule instances from RRuleSet Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/02-rruleset-class.md Returns a copy of all exclusive RRule instances within the set. These are represented as RRule objects. ```typescript exrules(): RRule[] ``` -------------------------------- ### Get all occurrences from RRuleSet Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/02-rruleset-class.md Retrieves all dates matching inclusive rules and dates, excluding those in exclusion rules/dates. This method is inherited from RRule. ```typescript all(iterator?: (d: Date, len: number) => boolean): Date[] ``` -------------------------------- ### Running Tests Source: https://github.com/jkbrzt/rrule/blob/master/README.md Execute the test suite for rrule.js to ensure code integrity and functionality. ```bash $ yarn test ``` -------------------------------- ### Get All Occurrences Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/08-quick-start-examples.md Retrieve all occurrences of a rule within its defined limits using the `all()` method. This is useful for generating a complete list of events. ```typescript import { RRule, datetime } from 'rrule' const rule = new RRule({ freq: RRule.DAILY, count: 30, dtstart: datetime(2023, 6, 1) }) const all = rule.all() console.log(all.length) // 30 ``` -------------------------------- ### Configure by Weekday with Positional Qualifiers Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/07-configuration.md Use `byweekday` to specify weekdays, optionally with positional qualifiers like `nth(1)` for the first occurrence or `nth(-1)` for the last. Behavior varies by frequency, affecting monthly and yearly rules by occurrence count. ```typescript new RRule({ freq: RRule.WEEKLY, byweekday: [RRule.MO, RRule.FR] }) ``` ```typescript new RRule({ freq: RRule.MONTHLY, byweekday: [RRule.MO.nth(1), RRule.MO.nth(3)] }) ``` ```typescript new RRule({ freq: RRule.MONTHLY, byweekday: RRule.FR.nth(-1) }) ``` ```typescript new RRule({ freq: RRule.YEARLY, bymonth: 11, byweekday: RRule.TH.nth(4) }) ``` -------------------------------- ### Helper Functions Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/README.md Documentation for utility functions provided by the rrule.js library. ```APIDOC ## Helper Functions ### Description Documentation for utility functions provided by the rrule.js library. ### Functions - `datetime(options)`: Creates a UTC date object. - `isValidDate(date)`: Checks if a value is a valid date. - `Weekday.fromStr(str)`: Creates a Weekday object from a string. - `Weekday.nth(weekday, n)`: Creates a Weekday object with an nth occurrence. ``` -------------------------------- ### Create Daily Recurrence Rule Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/API-SUMMARY.md Generates a recurrence rule for a daily frequency, repeating a specified number of times starting from a given date. ```typescript new RRule({ freq: RRule.DAILY, count: 10, dtstart: datetime(2023, 1, 1) }) ``` -------------------------------- ### RRule Constructor Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/01-rrule-class.md Initializes a new RRule instance with specified options for recurrence. The `freq` option is mandatory. Caching can be disabled by setting `noCache` to true. ```APIDOC ## new RRule(options?: Partial, noCache?: boolean) ### Description Constructs a new RRule object to define a recurrence pattern. The `options` object configures the recurrence, with `freq` being a required property. The `noCache` parameter can be used to disable internal caching for performance tuning. ### Parameters #### Options Object (`options`) - **freq** (Frequency) - Required - The frequency of the recurrence (e.g., `RRule.YEARLY`, `RRule.MONTHLY`). - **interval** (number) - Optional - The interval between recurrences of the frequency. Default is 1. - **count** (number) - Optional - The number of recurrences to generate. - **until** (Date) - Optional - The date/datetime at which the recurrence should end. - **dtstart** (Date) - Optional - The start date/datetime for the recurrence. - **wkst** (DayOfWeek) - Optional - The start day of the week for weekly recurrences. Defaults to `RRule.MO`. - **byweekday** (Array) - Optional - Specifies particular days of the week for the recurrence. - **bymonthday** (Array) - Optional - Specifies particular days of the month for the recurrence. - **byyearday** (Array) - Optional - Specifies particular days of the year for the recurrence. - **byweekno** (Array) - Optional - Specifies particular week numbers of the year for the recurrence. - **byday** (Array) - Optional - Specifies particular days of the month for the recurrence (can be used with `bymonthday`). - **byhour** (Array) - Optional - Specifies particular hours for the recurrence. - **byminute** (Array) - Optional - Specifies particular minutes for the recurrence. - **bysecond** (Array) - Optional - Specifies particular seconds for the recurrence. - **byeaster** (number) - Optional - Specifies the number of days relative to Easter for the recurrence. #### `noCache` Parameter - **noCache** (boolean) - Optional - If `true`, disables caching of generated dates. Defaults to `false`. ### Throws - `Error` if `options` contains invalid keys, invalid dates, or an invalid frequency value. ### Example ```typescript import { RRule, datetime } from 'rrule' // Every week on Monday and Friday until end of 2012 const rule = new RRule({ freq: RRule.WEEKLY, interval: 1, byweekday: [RRule.MO, RRule.FR], dtstart: datetime(2012, 1, 1, 10, 30), until: datetime(2012, 12, 31) }) // Generate all dates const dates = rule.all() ``` ``` -------------------------------- ### RRule all() Method Example Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/01-rrule-class.md Retrieves all occurrences matching the rule. An optional iterator can control the process for rules without defined end points. ```typescript const rule = new RRule({ freq: RRule.DAILY, count: 100, dtstart: datetime(2023, 1, 1) }) // Get all 100 dates const allDates = rule.all() // Get only first 5 dates using iterator const firstFive = rule.all((date, index) => index < 5) ``` -------------------------------- ### RRule Constructor Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/API-SUMMARY.md Initializes a new RRule instance with specified options for recurrence rules. ```APIDOC ## new RRule(options?: Partial, noCache?: boolean) ### Description Constructs a new RRule object. You can provide an options object to define the recurrence rule or initialize an empty rule. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **options** (Partial) - Optional - An object containing the recurrence rule options. * **noCache** (boolean) - Optional - If true, disables caching for this instance. ``` -------------------------------- ### Get all occurrences with RRule.all() Source: https://github.com/jkbrzt/rrule/blob/master/README.md Retrieves all dates matching the rule. An optional iterator function can be provided to limit the number of results or stop iteration early. ```javascript rule.all()[ ('2012-02-01T10:30:00.000Z', '2012-05-01T10:30:00.000Z', '2012-07-01T10:30:00.000Z', '2012-07-02T10:30:00.000Z') ] ``` ```javascript rule.all(function (date, i) { return i < 2 })[('2012-02-01T10:30:00.000Z', '2012-05-01T10:30:00.000Z')] ``` -------------------------------- ### RRule Initialization with Static Constants Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/03-types.md Initializes an RRule using static constants for daily recurrence. This method is an alternative to using the Frequency enum directly. ```typescript // Or use static constants const dailyRule = new RRule({ freq: RRule.DAILY, dtstart: datetime(2023, 1, 1), count: 30 }) ``` -------------------------------- ### Get occurrences between two dates from RRuleSet Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/02-rruleset-class.md Returns occurrences between two specified dates, respecting all inclusive and exclusive rules. This method is inherited from RRule. ```typescript between( after: Date, before: Date, inc?: boolean, iterator?: (d: Date, len: number) => boolean ): Date[] ``` -------------------------------- ### Default RRule Configuration Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/07-configuration.md Shows the default values for RRule options when they are omitted, demonstrating the full set of options and their inferred defaults. ```typescript const rule = new RRule({ freq: RRule.DAILY }) // Equivalent to: const rule = new RRule({ freq: RRule.DAILY, dtstart: new Date(), // Current date/time interval: 1, wkst: RRule.MO, // ISO 8601 week start count: null, until: null, tzid: null, bysetpos: null, bymonth: null, // Defaults inferred for other by* based on dtstart bymonthday: null, // and frequency byyearday: null, byweekno: null, byweekday: null, byhour: null, byminute: null, bysecond: null, byeaster: null }) ``` -------------------------------- ### Specifying Weekdays in RRule Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/03-types.md Demonstrates equivalent ways to specify weekdays using string constants, numbers, or Weekday instances when creating a weekly recurrence rule. Also shows how to use the nth() selector for specific occurrences within a month. ```typescript // All equivalent ways to specify Monday and Friday new RRule({ freq: RRule.WEEKLY, byweekday: ['MO', 'FR'] // string form }) ``` ```typescript new RRule({ freq: RRule.WEEKLY, byweekday: [0, 4] // number form (0=MO, 4=FR) }) ``` ```typescript new RRule({ freq: RRule.WEEKLY, byweekday: [RRule.MO, RRule.FR] // Weekday instances }) ``` ```typescript // nth() selector (first and last Friday of month) new RRule({ freq: RRule.MONTHLY, byweekday: [RRule.FR.nth(1), RRule.FR.nth(-1)] }) ``` -------------------------------- ### Get All Occurrences from RRuleSet Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/API-SUMMARY.md Calculates and returns all occurrences of the RRuleSet, optionally applying an iterator function to each occurrence. If no iterator is provided, it returns an array of Date objects. ```typescript all(iterator?) ``` -------------------------------- ### Get Occurrences in Range Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/08-quick-start-examples.md Use the `between()` method to fetch all occurrences of a rule that fall within a specified date range. This is ideal for calendar views or time-based reports. ```typescript import { RRule, datetime } from 'rrule' const rule = new RRule({ freq: RRule.WEEKLY, byweekday: RRule.MO, until: datetime(2024, 12, 31), dtstart: datetime(2023, 1, 2) }) // Get all Mondays in June 2023 const juneMondays = rule.between( datetime(2023, 6, 1), datetime(2023, 6, 30) ) ``` -------------------------------- ### Static fromText() Source: https://github.com/jkbrzt/rrule/blob/master/_autodocs/01-rrule-class.md Creates an RRule instance directly from natural language text. ```APIDOC ## Static fromText() ### Description Creates an `RRule` instance from natural language text. ### Parameters #### Path Parameters - **text** (string) - Required - Recurrence description in English. - **language** (Language) - Optional - Language definition (defaults to `ENGLISH`). ### Returns New `RRule` instance. ### Example ```typescript const rule = RRule.fromText('every month for 6 times') const dates = rule.all() ``` ```