parse static method

RecurrenceRule? parse(
  1. String ruleString
)

Implementation

static RecurrenceRule? parse(String ruleString) {
  final parts = ruleString.split(';');
  Frequancy? frequency;
  int interval = 1;
  DateTime? until;
  List<ByDay>? byDay;

  for (var part in parts) {
    final keyValue = part.split('=');
    if (keyValue.length == 2) {
      final key = keyValue[0];
      final value = keyValue[1];
      switch (key) {
        case 'FREQ':
          frequency = Frequancy.values.firstWhere((e)=> e.name == value,) ;
          break;
        case 'INTERVAL':
          interval = int.tryParse(value) ?? 1;
          break;
        case 'UNTIL':
          until = DateTime.parse(value.replaceAll('Z', ''));
          break;
        case 'BYDAY':
          byDay = value.split(',').map((e)=> ByDay.parse(e)).toList();
          break;
      }
    }
  }

  if (frequency != null) {
    return RecurrenceRule(
      frequency: frequency,
      interval: interval,
      until: until,
      byDay: byDay,
    );
  }
  return null;
}