TimeZoneTransition.fromICalString constructor

TimeZoneTransition.fromICalString(
  1. String icalString
)

Implementation

factory TimeZoneTransition.fromICalString(String icalString) {
  final lines = icalString.split('\n');
  bool? isDaylight;
  DateTime? dateTime;
  String? timeZoneOffset;
  for (final line in lines) {
    if (line.startsWith('DTSTART:')) {
      dateTime = DateTime.parse(line.substring(8));
    } else if (line.startsWith('TZOFFSETTO:')) {
      timeZoneOffset = line.substring(12);
    } else if (line.startsWith('TZOFFSETFROM:')) {
    } else if (line.startsWith('RRULE:')) {
    } else if (line.startsWith('BEGIN:')) {
      isDaylight = line.endsWith(':DAYLIGHT');
    }
  }
  if (isDaylight == null || dateTime == null || timeZoneOffset == null) {
    throw FormatException('Invalid iCalendar string: $icalString');
  }
  return TimeZoneTransition(
      isDaylight: isDaylight,
      dateTime: dateTime,
      timeZoneOffset: timeZoneOffset);
}