Skip to content

RecurrentScheduledTrigger

A trigger that triggers based on a recurrent scheduled date and time.

Supports daily, weekly and monthly recurrences. Yearly recurrence is not supported, since data sampling is not intended to run on such long time scales.

Here are a couple of examples:

 // trigger every day at 13:30
 RecurrentScheduledTrigger(type: RecurrentType.daily, time: TimeOfDay(hour: 13, minute: 30));

 // trigger every other day at 13:30
 RecurrentScheduledTrigger(type: RecurrentType.daily, separationCount: 1, time: TimeOfDay(hour: 13, minute: 30));

 // trigger every wednesday at 12:23
 RecurrentScheduledTrigger(type: RecurrentType.weekly, dayOfWeek: DateTime.wednesday, time: TimeOfDay(hour: 12, minute: 23));

 // trigger every 2nd monday at 12:23
 RecurrentScheduledTrigger(type: RecurrentType.weekly, dayOfWeek: DateTime.monday, separationCount: 1, time: TimeOfDay(hour: 12, minute: 23));

 // trigger monthly in the second week on a monday at 14:30
 RecurrentScheduledTrigger(type: RecurrentType.monthly, weekOfMonth: 2, dayOfWeek: DateTime.monday, time: TimeOfDay(hour: 14, minute: 30));

 // trigger quarterly on the 11th day of the first month in each quarter at 21:30
 RecurrentScheduledTrigger(type: RecurrentType.monthly, dayOfMonth: 11, separationCount: 2, time: TimeOfDay(hour: 21, minute: 30));

Thanks to Shantanu Kher for inspiration in his blog post on Again and Again! Managing Recurring Events In a Data Model. We are, however, not using yearly recurrence.

Inheritance
Implemented types
Annotations

Constructors

RecurrentScheduledTrigger.fromJson

RecurrentScheduledTrigger.fromJson(
  1. Map<String, dynamic> json
)

RecurrentScheduledTrigger

RecurrentScheduledTrigger({
  1. RecurrentType type = RecurrentType.daily,
  2. TimeOfDay time = const TimeOfDay(),
  3. DateTime? end,
  4. int separationCount = 0,
  5. int? maxNumberOfSampling,
  6. int? dayOfWeek,
  7. int? weekOfMonth,
  8. int? dayOfMonth,
  9. Duration? duration,
})

Creates a trigger that triggers based on a recurrent scheduled date and time.

dayOfWeek is required for weekly recurrence, and dayOfMonth or weekOfMonth for monthly recurrence. The duration parameter is not used.

Constants

daysPerMonth

int const daysPerMonth

The number of days used as one month when computing period.

daysPerWeek

int const daysPerWeek

Properties

dayOfMonth

int? dayOfMonth
getter/setter pair

If monthly recurrence, specify the day of the month.

Used in cases when an event is scheduled on a particular day of the month, say the 25th. Possible numbers are 1..31 counting from the start of a month.

dayOfWeek

int? dayOfWeek
getter/setter pair

If weekly recurrence, specify which day of week.

Uses the DateTime.weekday values, i.e. 1 is Monday and 7 is Sunday.

end

DateTime? end
getter/setter pair

End time and date. If null, this trigger keeps triggering forever.

firstOccurrence

DateTime get firstOccurrence

The date and time of the first occurrence of this trigger after now.

fromJsonFunction

Function get fromJsonFunction
override

The function which can convert a JSON string to an object of this type.

maxNumberOfSampling

int? maxNumberOfSampling
getter/setter pair

Maximum number of samplings.

There are times when we do not know the exact end time and date for recurrent sampling. But we might know how many occurrences (samplings) are needed to complete it.

period

Duration get period

The time between two triggers.

A month is counted as daysPerMonth days, so monthly triggers drift over time.

separationCount

int separationCount
getter/setter pair

Separation between recurrences.

This value signifies the interval (in days, weeks or months) before the next event instance is allowed. For example, if an event needs to be configured for every other week, then separationCount is 1. The default value is 0.

time

TimeOfDay time
getter/setter pair

The time of day of this trigger. Default is midnight.

type

RecurrentType type
getter/setter pair

The type of recurrence - daily, weekly or monthly.

weekOfMonth

int? weekOfMonth
getter/setter pair

If monthly recurrence, specify the week in the month.

weekOfMonth is used for samplings that are scheduled for a certain week of the month – i.e., the first, second, etc. Possible values are 1,2,3,4. The first week is the week of the first Monday of a month. For example, the first week of September 2020 is the week starting on Monday 2020-09-07.

Methods

nextMonthlyDay

DateTime nextMonthlyDay(
  1. DateTime fromDate
)

The next day in a monthly occurrence from the given fromDate.

toJson

Map<String, dynamic> toJson()
override

Return a JSON encoding of this object.

toString

String toString()
override

A string representation of this object.

Some classes have a default textual representation, often paired with a static parse function (like int.parse). These classes will provide the textual representation as their string representation.

Other classes have no meaningful textual representation that a program will care about. Such classes will typically override toString to provide useful information when inspecting the object, mainly for debugging or logging.