timezonesFor method
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) {
zones = List<Timezone>.from(matches.first.timezones, growable: false);
zones.sort((a, b) => a.gmtOffset.compareTo(b.gmtOffset));
} else {
zones = [];
}
return zones;
}