getLocation function
Find Location by its name.
final detroit = getLocation('America/Detroit');
Implementation
Location getLocation(String pgTimeZone) {
final tzLocations = timeZoneDatabase.locations.entries
.where((e) {
return e.key.toLowerCase() == pgTimeZone ||
e.value.currentTimeZone.abbreviation.toLowerCase() == pgTimeZone;
})
.map((e) => e.value)
.toList();
if (tzLocations.isEmpty) {
throw LocationNotFoundException(
'Location with the name "$pgTimeZone" doesn\'t exist');
}
final tzLocation = tzLocations.first;
return tzLocation;
}