TimeZoneComponent.fromCrawledBlock constructor

TimeZoneComponent.fromCrawledBlock(
  1. CrawledBlock block
)

Implementation

factory TimeZoneComponent.fromCrawledBlock(CrawledBlock block) {
  assert(
    block.blockName.toUpperCase() == "VTIMEZONE",
    "Received invalid block: ${block.blockName}",
  );

  TimeZoneIdentifierProperty? timeZoneIdentifier;
  LastModifiedProperty? lastModified;
  TimeZoneUrlProperty? timeZoneUrl;
  List<StandardTimeZoneComponent>? standardTimeZones;
  List<DaylightTimeZoneComponent>? daylightTimeZones;

  for (var e in block.properties) {
    switch (e.name.toUpperCase()) {
      case "TZID":
        timeZoneIdentifier =
            TimeZoneIdentifierProperty.fromCrawledProperty(e);
        break;
      case "LAST-MODIFIED":
        lastModified = LastModifiedProperty.fromCrawledProperty(e);
        break;
      case "TZURL":
        timeZoneUrl = TimeZoneUrlProperty.fromCrawledProperty(e);
        break;
      default:
        print("Unknown property encountered in TimeZoneComponent: ${e.name}");
    }
  }

  for (var e in block.nestedBlocks) {
    switch (e.blockName.toUpperCase()) {
      case "STANDARD":
        standardTimeZones ??= [];
        standardTimeZones.add(StandardTimeZoneComponent.fromCrawledBlock(e));
        break;
      case "DAYLIGHT":
        daylightTimeZones ??= [];
        daylightTimeZones.add(DaylightTimeZoneComponent.fromCrawledBlock(e));
        break;
      default:
        print(
            "Unknown component encountered in TimeZoneComponent: ${e.blockName}");
    }
  }

  assert(
    timeZoneIdentifier != null,
    "[timeZoneIdentifier] cannot be null",
  );

  return TimeZoneComponent(
    timeZoneIdentifier: timeZoneIdentifier!,
    lastModified: lastModified,
    timeZoneUrl: timeZoneUrl,
    standardTimeZones: standardTimeZones,
    daylightTimeZones: daylightTimeZones,
  );
}