parse method

  1. @override
CronSchedule parse()

Returns the parsed schedule.

Implementation

@override
CronSchedule parse() {
  List<String?> fields = _value
      .split(_whitespaceRegExp)
      .where((part) => part.isNotEmpty)
      .toList();

  if (fields.length < 5) {
    throw ScheduleParseError(
      '''
The Cron format needs to consist of 5 fields at least.
 -----------
 * * * * * *
 -----------
 | | | | | |
 | | | | | +-- Weekdays  (range: 0-7)
 | | | | +---- Months    (range: 1-12)
 | | | +------ Days      (range: 1-31)
 | | +-------- Hours     (range: 0-23)
 | +---------- Minutes   (range: 0-59)
 +------------ Seconds   (range: 0-59, it will be interpreted as "*" if it's omitted)''',
    );
  }

  fields = [
    if (fields.length == 5) null,
    ...fields,
  ];

  return _parse(
    seconds: fields[0],
    minutes: fields[1],
    hours: fields[2],
    days: fields[3],
    months: fields[4],
    weekdays: fields[5],
  );
}