パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v0.2.18

rrule

iCalendar RFC で定義された繰り返しルールの解析と計算

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
8.5万
いいね数
94
Pub ポイント
150

パッケージをインストール

flutter pub add rrule

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

rrule パッケージは、iCalendar RFC 標準に従って繰り返しルールの解析と計算を可能にします。開発者が日次、週次、月次スケジュールなどの複雑な繰り返しイベントを定義できるようにし、開始日、終了条件、例外などについて正確な制御が可能です。これは、複数のプラットフォームで正確な繰り返しロジックが必要なカレンダーアプリ、タスクスケジューリング、イベント管理システムにおいて特に役立ちます。

用途

  • 繰り返しイベント付きのカレンダーアプリ
  • タスクスケジューリングシステム
  • イベント企画ツール
  • 会議の再スケジューリング機能
  • 自動リマインダー システム

主な機能

  • RFC準拠の繰り返しルールの解析
  • 複雑な繰り返しパターンのサポート
  • タイムゾーン対応の日付計算
  • 繰り返しイベントの例外処理
  • クロスプラットフォーム互換性

適している対象

  • カレンダー機能を構築する開発者
  • 繰り返しイベント論理を必要とするアプリケーション
  • iCalendar標準準拠を必要とするプロジェクト
  • マルチプラットフォーム日時ユーティリティ

注意事項

  • iCalendar RFC 5545 の理解が必要です
  • 非常に大きな繰り返しセットではパフォーマンスへの影響がある可能性があります
  • 基本的な使用方法以外のドキュメントは限られている
  • リアルタイムの高頻度更新には最適化されていない

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

🔁 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 and Dutch are
// 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.

カテゴリー

依存関係

依存関係一覧 4 件

ソースリポジトリ

このパッケージを使用しているプロジェクト