timezonesFor method

List<Timezone> timezonesFor(
  1. GeoCodedIdentity target
)

Finds the Timezones for the Country identified by the target. Throws an ArgumentError, if the target is invalid.

Returns: A List of Timezones for the Country identified by the target or an empty list if a valid target doesn't match any Country

Implementation

List<Timezone> timezonesFor(GeoCodedIdentity target) {
  if (!target.isValid) {
    throw ArgumentError.value(
      target,
      'target',
      'A valid GeoCodedIdentity must be provided.',
    );
  }

  late final List<Timezone> zones;
  final matches = countries.where((c) => target.isMatch(c));
  if (matches.isNotEmpty) {
    final matchZones = matches.first.timezones ?? [];
    zones = List<Timezone>.from(matchZones, growable: false);
    zones.sort((a, b) => a.gmtOffset.compareTo(b.gmtOffset));
  } else {
    zones = [];
  }
  return zones;
}