rrule 패키지는 iCalendar RFC 표준에 따라 반복 규칙을 분석하고 계산할 수 있도록 합니다. 개발자가 시작 날짜, 종료 조건 및 예외를 정밀하게 제어할 수 있는 일일, 주간 또는 월간 스케줄과 같은 복잡한 반복 이벤트를 정의할 수 있습니다. 이는 여러 플랫폼에서 정확한 반복 로직이 필요한 캘린더 애플리케이션, 작업 스케줄링 및 이벤트 관리 시스템에 특히 유용합니다.
사용 사례
반복 이벤트가 있는 캘린더 앱
작업 스케줄링 시스템
이벤트 기획 도구
회의 재스케줄링 기능
자동 알림 시스템
주요 기능
RFC 준수 반복 규칙 분석
복잡한 반복 패턴 지원
시간대 인식 날짜 계산
반복 이벤트에 대한 예외 처리
크로스 플랫폼 호환성
적합한 대상
캘린더 기능을 구축하는 개발자
반복 이벤트 로직이 필요한 응용 프로그램
iCalendar 표준 준수를 필요로 하는 프로젝트
다중 플랫폼 날짜/시간 유틸리티
고려 사항
iCalendar RFC 5545 이해 필요
매우 큰 반복 세트에서는 성능에 영향을 미칠 수 있습니다
기본 사용법 외에 문서가 제한적
실시간 고주기 업데이트에 최적화되지 않음
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
🔁 Recurrence rule parsing & calculation as defined in the iCalendar RFC
// Every two weeks on Tuesday and Thursday, but only in December.final rrule = RecurrenceRule(
frequency: Frequency.weekly,
interval: 2,
byWeekDays: {
ByWeekDayEntry(DateTime.tuesday),
ByWeekDayEntry(DateTime.thursday),
},
byMonths: {12},
);
And get its recurrences by evaluating it from a start date:
⚠️ rrule doesn't care about any time-zone-related stuff.
All supplied DateTimes must have isUtc set to true (because UTC doesn't have complications like summer and winter time), but the actual time zone is then ignored, e.g., when generating human-readable text.
If you have a DateTime instance in the local time zone, you can use rrule's helper dateTime.copyWith(isUtc: true) which keeps the date and time but sets isUtc to true.
To convert the generated instances back to your local time zone, you can use dateTime.copyWith(isUtc: false).
To limit returned instances (besides using RecurrenceRule.until or RecurrenceRule.count), you can use Dart's default Iterable functions:
final firstThreeInstances = instances.take(3);
final onlyThisYear = instances.takeWhile(
(instance) => instance.year == DateTime.now().year,
);
final startingNextYear = instances.where(
(instance) => instance.year > DateTime.now().year,
);
// First, load the localizations (currently, only English and Dutch are// supported):final l10n = awaitRruleL10nEn.create();
final rrule = RecurrenceRule.fromString(
'RRULE:FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,TH;BYMONTH=12',
);
final text = 'Every other week in December on Tuesday & Thursday';
assert(rrule.toText(l10n: l10n) == string); // true
(Same RRULE as the first one)
A few more examples:
RRULE:INTERVAL=4;FREQ=HOURLY: Every 4 hours
RRULE:FREQ=DAILY;BYSETPOS=1,-2;BYMONTH=1,12;BYMONTHDAY=1,-1: Daily in January & December on the 1st & 2nd-to-last instance of the 1st & last day of the month
RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR: Weekly on weekdays
RRULE:INTERVAL=2;FREQ=WEEKLY: Every other week
RRULE:FREQ=MONTHLY;BYDAY=-3TU: Monthly on the 3rd-to-last Tuesday
RRULE:FREQ=YEARLY;BYDAY=+13FR: Annually on the 13th Friday of the year
RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYWEEKNO=1,-1;BYYEARDAY=1,-1;BYMONTHDAY=1,-1;BYDAY=MO,WE: Annually on the 1st & 2nd-to-last instance of every Monday & Wednesday that are also the 1st or last day of the month, that are also the 1st or last day of the year, that are also in the 1st or last week of the year, and that are also in January or December
While this already supports really complex RRULEs, some of them are not (yet) supported. See RecurrenceRule.canFullyConvertToText for more information.
JSON conversion
You can convert between RecurrenceRules and jCal/RFC 7265-compliant JSON using the following convenience methods:
custom week starts are not supported (WKST in the specification) – Monday is the only valid value (encoded as MO)
leap seconds are not supported (limitation of Dart's DateTime)
only years 0–9999 in the Common Era are supported (limitation of the iCalendar RFC, but if you have a use case, this should be easy to extend)
Thanks
The recurrence calculation code of RecurrencRules is mostly a partial port of rrule.js, though with a lot of modifications to use Dart's DateTime and not having to do date/time calculations manually. You can find the license of rrule.js in the file LICENSE-rrule.js.txt.