All Projects → JonasWanke → rrule

JonasWanke / rrule

Licence: Apache-2.0 license
🔁 Recurrence rule parsing & calculation as defined in the iCalendar RFC

Programming Languages

dart
5743 projects
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to rrule

node-ical
NodeJS class for parsing iCalendar/ICS files
Stars: ✭ 53 (+70.97%)
Mutual labels:  icalendar, ical
iCalKit
📅 Parse and generate iCalendar (.ics) files in Swift
Stars: ✭ 54 (+74.19%)
Mutual labels:  icalendar, ical
remarkable-calendar-creator
Create calendars to display on a reMarkable device as the suspend screen or to write notes on, including events from your own online iCal calendar
Stars: ✭ 28 (-9.68%)
Mutual labels:  icalendar, ical
ical
📅 Golang iCalendar lexer/parser implementing RFC 5545
Stars: ✭ 28 (-9.68%)
Mutual labels:  icalendar, ical
Rrule
JavaScript library for working with recurrence rules for calendar dates as defined in the iCalendar RFC and more.
Stars: ✭ 2,249 (+7154.84%)
Mutual labels:  rrule, recurrence-rules
rrule-go
Go library for working with recurrence rules for calendar dates.
Stars: ✭ 23 (-25.81%)
Mutual labels:  rrule, recurrence-rules
THCalendar
Calendar like iOS
Stars: ✭ 21 (-32.26%)
Mutual labels:  icalendar, ical
rfc5545-rrule
RFC5545 RRule library for JavaScript
Stars: ✭ 22 (-29.03%)
Mutual labels:  ical, rrule
icalparser
Simple ical parser for PHP
Stars: ✭ 56 (+80.65%)
Mutual labels:  icalendar, ical
kcl-timetable
Utilities in Python3 to fetch the KCL Timetable for a user, or export it as iCalendar (*.ics for Google or Apple)!
Stars: ✭ 14 (-54.84%)
Mutual labels:  icalendar
webcalendar
WebCalendar is a PHP application used to maintain a calendar for a single user or an intranet group of users. It can also be configured as an event calendar.
Stars: ✭ 113 (+264.52%)
Mutual labels:  icalendar
python-jicson
python ics to json lib
Stars: ✭ 11 (-64.52%)
Mutual labels:  icalendar
jpl-space-calendar
An app for parsing and publishing the JPL Space Calendar in JSON and ICalendar formats.
Stars: ✭ 13 (-58.06%)
Mutual labels:  icalendar
weather-calendar-feed
Display yr.no weather (supports the entire Earth) forecasts with highly customizable Event titles in your Google Calendar, Android phone, iPhone, Outlook or other iCalendar app
Stars: ✭ 16 (-48.39%)
Mutual labels:  icalendar
calcardbackup
calcardbackup: moved to https://codeberg.org/BernieO/calcardbackup
Stars: ✭ 67 (+116.13%)
Mutual labels:  icalendar
ChinaPublicCalendar
搜集各种公共事件,包括假日、国际节日、传统节日、节气和电影上映时间等公共日历以 Calendar(RFC5545) 文件格式提供。
Stars: ✭ 58 (+87.1%)
Mutual labels:  ical
ADE-Scheduler
A webapp for UCLouvain's ADE scheduling tool.
Stars: ✭ 22 (-29.03%)
Mutual labels:  ical
cocktail
Elixir date recurrence library based on iCalendar events
Stars: ✭ 115 (+270.97%)
Mutual labels:  icalendar
Radicale
A simple CalDAV (calendar) and CardDAV (contact) server.
Stars: ✭ 2,268 (+7216.13%)
Mutual labels:  icalendar
NUAA ClassSchedule
NUAA_ClassSchedule 登录南京航空航天大学新教务系统,获取课表及考试信息,解析后生成iCal日历及xlsx表格文件,进而导入Outlook等日历...
Stars: ✭ 29 (-6.45%)
Mutual labels:  icalendar

🔁 Recurrence rule parsing & calculation as defined in the iCalendar RFC

Build, Test & Lint Coverage

How to use this package

Create a RecurrenceRule:

// 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:

final Iterable<DateTime> instances = rrule.getInstances(
  start: DateTime.now().copyWith(isUtc: true),
);

⚠️ 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,
);

Machine-readable String conversion

You can convert between RecurrenceRules and iCalendar/RFC 5545-compliant Strings by using RecurrenceRuleStringCodec or the following convenience methods:

final string = 'RRULE:FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,TH;BYMONTH=12';
final rrule = RecurrenceRule.fromString(string);

assert(rrule.toString() == string); // true

(Same RRULE as the first one)

Human-readable Text conversion

You can convert a RecurrenceRule to a human-readable Strings by using RecurrenceRule.toText():

// First, load the localizations (currently, only English is supported):
final l10n = await RruleL10nEn.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:

final json = <String, dynamic>{
  'freq': 'WEEKLY',
  'interval': 2,
  'byday': ['TU', 'TH'],
  'bymonth': [12],
};
final rrule = RecurrenceRule.fromJson(json);

expect(rrule.toJson(), json);

(Same RRULE as the first one)

Limitations

  • 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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].