UNPKG

scriptable-testlab

Version:

A lightweight, efficient tool designed to manage and update scripts for Scriptable.

374 lines (339 loc) 13.6 kB
/// <reference types="scriptable-ios" /> import {AbsRecurrenceRule} from 'scriptable-abstract'; /** * Interface representing the state of a recurrence rule */ interface RecurrenceRuleState { interval: number; endDate?: Date; occurrenceCount?: number; daysOfTheWeek?: readonly number[]; daysOfTheMonth?: readonly number[]; monthsOfTheYear?: readonly number[]; weeksOfTheYear?: readonly number[]; daysOfTheYear?: readonly number[]; setPositions?: readonly number[]; } /** * Mock implementation of Scriptable's RecurrenceRule class */ export class MockRecurrenceRule extends AbsRecurrenceRule<RecurrenceRuleState> { private constructor(state: RecurrenceRuleState) { super(state); } get asRecurrenceRule(): RecurrenceRule { return this as unknown as RecurrenceRule; } get interval(): number { return this.state.interval; } get endDate(): Date | null { return this.state.endDate ?? null; } get occurrenceCount(): number | null { return this.state.occurrenceCount ?? null; } get daysOfTheWeek(): readonly number[] { return this.state.daysOfTheWeek ?? []; } get daysOfTheMonth(): readonly number[] { return this.state.daysOfTheMonth ?? []; } get monthsOfTheYear(): readonly number[] { return this.state.monthsOfTheYear ?? []; } get weeksOfTheYear(): readonly number[] { return this.state.weeksOfTheYear ?? []; } get daysOfTheYear(): readonly number[] { return this.state.daysOfTheYear ?? []; } get setPositions(): readonly number[] { return this.state.setPositions ?? []; } /** * Constructs a daily recurrence rule * @param interval - Interval at which to repeat the rule */ static daily(interval: number): RecurrenceRule { return new MockRecurrenceRule({interval}).asRecurrenceRule; } /** * Constructs a daily recurrence rule with an end date * @param interval - Interval at which to repeat the rule * @param endDate - Date at which the recurrence rule should end */ static dailyEndDate(interval: number, endDate: Date): RecurrenceRule { return new MockRecurrenceRule({interval, endDate}).asRecurrenceRule; } /** * Constructs a daily recurrence rule with an occurrence count * @param interval - Interval at which to repeat the rule * @param occurrenceCount - Number of times the rule should repeat before it ends */ static dailyOccurrenceCount(interval: number, occurrenceCount: number): RecurrenceRule { return new MockRecurrenceRule({interval, occurrenceCount}).asRecurrenceRule; } /** * Constructs a weekly recurrence rule * @param interval - Interval at which to repeat the rule */ static weekly(interval: number): RecurrenceRule { return new MockRecurrenceRule({interval}).asRecurrenceRule; } /** * Constructs a weekly recurrence rule with an end date * @param interval - Interval at which to repeat the rule * @param endDate - Date at which the recurrence rule should end */ static weeklyEndDate(interval: number, endDate: Date): RecurrenceRule { return new MockRecurrenceRule({interval, endDate}).asRecurrenceRule; } /** * Constructs a weekly recurrence rule with an occurrence count * @param interval - Interval at which to repeat the rule * @param occurrenceCount - Number of times the rule should repeat before it ends */ static weeklyOccurrenceCount(interval: number, occurrenceCount: number): RecurrenceRule { return new MockRecurrenceRule({interval, occurrenceCount}).asRecurrenceRule; } /** * Constructs a monthly recurrence rule * @param interval - Interval at which to repeat the rule */ static monthly(interval: number): RecurrenceRule { return new MockRecurrenceRule({interval}).asRecurrenceRule; } /** * Constructs a monthly recurrence rule with an end date * @param interval - Interval at which to repeat the rule * @param endDate - Date at which the recurrence rule should end */ static monthlyEndDate(interval: number, endDate: Date): RecurrenceRule { return new MockRecurrenceRule({interval, endDate}).asRecurrenceRule; } /** * Constructs a monthly recurrence rule with an occurrence count * @param interval - Interval at which to repeat the rule * @param occurrenceCount - Number of times the rule should repeat before it ends */ static monthlyOccurrenceCount(interval: number, occurrenceCount: number): RecurrenceRule { return new MockRecurrenceRule({interval, occurrenceCount}).asRecurrenceRule; } /** * Constructs a yearly recurrence rule * @param interval - Interval at which to repeat the rule */ static yearly(interval: number): RecurrenceRule { return new MockRecurrenceRule({interval}).asRecurrenceRule; } /** * Constructs a yearly recurrence rule with an end date * @param interval - Interval at which to repeat the rule * @param endDate - Date at which the recurrence rule should end */ static yearlyEndDate(interval: number, endDate: Date): RecurrenceRule { return new MockRecurrenceRule({interval, endDate}).asRecurrenceRule; } /** * Constructs a yearly recurrence rule with an occurrence count * @param interval - Interval at which to repeat the rule * @param occurrenceCount - Number of times the rule should repeat before it ends */ static yearlyOccurrenceCount(interval: number, occurrenceCount: number): RecurrenceRule { return new MockRecurrenceRule({interval, occurrenceCount}).asRecurrenceRule; } /** * Constructs a complex weekly recurrence rule * @param interval - Interval at which to repeat the rule * @param daysOfTheWeek - Days of the week to repeat the rule. Values range from 1 to 7, with Sunday being 1 * @param setPositions - Filters which recurrences to include in the rule's frequency */ static complexWeekly( interval: number, daysOfTheWeek: readonly number[], setPositions: readonly number[], ): RecurrenceRule { return new MockRecurrenceRule({interval, daysOfTheWeek, setPositions}).asRecurrenceRule; } /** * Constructs a complex weekly recurrence rule with an end date * @param interval - Interval at which to repeat the rule * @param daysOfTheWeek - Days of the week to repeat the rule. Values range from 1 to 7, with Sunday being 1 * @param setPositions - Filters which recurrences to include in the rule's frequency * @param endDate - Date at which the recurrence rule should end */ static complexWeeklyEndDate( interval: number, daysOfTheWeek: readonly number[], setPositions: readonly number[], endDate: Date, ): RecurrenceRule { return new MockRecurrenceRule({interval, daysOfTheWeek, setPositions, endDate}).asRecurrenceRule; } /** * Constructs a complex weekly recurrence rule with an occurrence count * @param interval - Interval at which to repeat the rule * @param daysOfTheWeek - Days of the week to repeat the rule. Values range from 1 to 7, with Sunday being 1 * @param setPositions - Filters which recurrences to include in the rule's frequency * @param occurrenceCount - Number of times the rule should repeat before it ends */ static complexWeeklyOccurrenceCount( interval: number, daysOfTheWeek: readonly number[], setPositions: readonly number[], occurrenceCount: number, ): RecurrenceRule { return new MockRecurrenceRule({ interval, daysOfTheWeek, setPositions, occurrenceCount, }).asRecurrenceRule; } /** * Constructs a complex monthly recurrence rule * @param interval - Interval at which to repeat the rule * @param daysOfTheWeek - Days of the week to repeat the rule. Values range from 1 to 7, with Sunday being 1 * @param daysOfTheMonth - Days of the month to repeat the rule. Values range from 1 to 31 and from -1 to -31 * @param setPositions - Filters which recurrences to include in the rule's frequency */ static complexMonthly( interval: number, daysOfTheWeek: readonly number[], daysOfTheMonth: readonly number[], setPositions: readonly number[], ): RecurrenceRule { return new MockRecurrenceRule({interval, daysOfTheWeek, daysOfTheMonth, setPositions}).asRecurrenceRule; } /** * Constructs a complex monthly recurrence rule with an end date * @param interval - Interval at which to repeat the rule * @param daysOfTheWeek - Days of the week to repeat the rule. Values range from 1 to 7, with Sunday being 1 * @param daysOfTheMonth - Days of the month to repeat the rule. Values range from 1 to 31 and from -1 to -31 * @param setPositions - Filters which recurrences to include in the rule's frequency * @param endDate - Date at which the recurrence rule should end */ static complexMonthlyEndDate( interval: number, daysOfTheWeek: readonly number[], daysOfTheMonth: readonly number[], setPositions: readonly number[], endDate: Date, ): RecurrenceRule { return new MockRecurrenceRule({ interval, daysOfTheWeek, daysOfTheMonth, setPositions, endDate, }).asRecurrenceRule; } /** * Constructs a complex monthly recurrence rule with an occurrence count * @param interval - Interval at which to repeat the rule * @param daysOfTheWeek - Days of the week to repeat the rule. Values range from 1 to 7, with Sunday being 1 * @param daysOfTheMonth - Days of the month to repeat the rule. Values range from 1 to 31 and from -1 to -31 * @param setPositions - Filters which recurrences to include in the rule's frequency * @param occurrenceCount - Number of times the rule should repeat before it ends */ static complexMonthlyOccurrenceCount( interval: number, daysOfTheWeek: readonly number[], daysOfTheMonth: readonly number[], setPositions: readonly number[], occurrenceCount: number, ): RecurrenceRule { return new MockRecurrenceRule({ interval, daysOfTheWeek, daysOfTheMonth, setPositions, occurrenceCount, }).asRecurrenceRule; } /** * Constructs a complex yearly recurrence rule * @param interval - Interval at which to repeat the rule * @param daysOfTheWeek - Days of the week to repeat the rule. Values range from 1 to 7, with Sunday being 1 * @param monthsOfTheYear - Months of the year to repeat the rule. Values range from 1 to 12 * @param weeksOfTheYear - Weeks of the year to repeat the rule. Values range from 1 to 53 and from -1 to -53 * @param daysOfTheYear - Days of the year to repeat the rule. Values range from 1 to 366 and from -1 to -366 * @param setPositions - Filters which recurrences to include in the rule's frequency */ static complexYearly( interval: number, daysOfTheWeek: readonly number[], monthsOfTheYear: readonly number[], weeksOfTheYear: readonly number[], daysOfTheYear: readonly number[], setPositions: readonly number[], ): RecurrenceRule { return new MockRecurrenceRule({ interval, daysOfTheWeek, monthsOfTheYear, weeksOfTheYear, daysOfTheYear, setPositions, }).asRecurrenceRule; } /** * Constructs a complex yearly recurrence rule with an end date * @param interval - Interval at which to repeat the rule * @param daysOfTheWeek - Days of the week to repeat the rule. Values range from 1 to 7, with Sunday being 1 * @param monthsOfTheYear - Months of the year to repeat the rule. Values range from 1 to 12 * @param weeksOfTheYear - Weeks of the year to repeat the rule. Values range from 1 to 53 and from -1 to -53 * @param daysOfTheYear - Days of the year to repeat the rule. Values range from 1 to 366 and from -1 to -366 * @param setPositions - Filters which recurrences to include in the rule's frequency * @param endDate - Date at which the recurrence rule should end */ static complexYearlyEndDate( interval: number, daysOfTheWeek: readonly number[], monthsOfTheYear: readonly number[], weeksOfTheYear: readonly number[], daysOfTheYear: readonly number[], setPositions: readonly number[], endDate: Date, ): RecurrenceRule { return new MockRecurrenceRule({ interval, daysOfTheWeek, monthsOfTheYear, weeksOfTheYear, daysOfTheYear, setPositions, endDate, }).asRecurrenceRule; } /** * Constructs a complex yearly recurrence rule with an occurrence count * @param interval - Interval at which to repeat the rule * @param daysOfTheWeek - Days of the week to repeat the rule. Values range from 1 to 7, with Sunday being 1 * @param monthsOfTheYear - Months of the year to repeat the rule. Values range from 1 to 12 * @param weeksOfTheYear - Weeks of the year to repeat the rule. Values range from 1 to 53 and from -1 to -53 * @param daysOfTheYear - Days of the year to repeat the rule. Values range from 1 to 366 and from -1 to -366 * @param setPositions - Filters which recurrences to include in the rule's frequency * @param occurrenceCount - Number of times the rule should repeat before it ends */ static complexYearlyOccurrenceCount( interval: number, daysOfTheWeek: readonly number[], monthsOfTheYear: readonly number[], weeksOfTheYear: readonly number[], daysOfTheYear: readonly number[], setPositions: readonly number[], occurrenceCount: number, ): RecurrenceRule { return new MockRecurrenceRule({ interval, daysOfTheWeek, monthsOfTheYear, weeksOfTheYear, daysOfTheYear, setPositions, occurrenceCount, }).asRecurrenceRule; } }