Simplify APIs exposed for time zone lookups

The libcore.timezone APIs may form the basis for some
new SystemApis. Before starting that process the API
surface is being rationalized to establish the core
use cases.

Test: Treehugger
Bug: 139091367
Change-Id: Ib615976fae76ceb98873a33e1e995542e691c9d0
This commit is contained in:
Neil Fuller
2019-08-19 20:27:45 +01:00
parent 3628bb3a64
commit babab5cd6a

View File

@@ -34,11 +34,14 @@ import androidx.core.text.TextDirectionHeuristicsCompat;
import com.android.settingslib.R;
import libcore.timezone.CountryTimeZones;
import libcore.timezone.CountryTimeZones.TimeZoneMapping;
import libcore.timezone.TimeZoneFinder;
import org.xmlpull.v1.XmlPullParserException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
@@ -387,7 +390,21 @@ public class ZoneGetter {
@VisibleForTesting
public List<String> lookupTimeZoneIdsByCountry(String country) {
return TimeZoneFinder.getInstance().lookupTimeZoneIdsByCountry(country);
final CountryTimeZones countryTimeZones =
TimeZoneFinder.getInstance().lookupCountryTimeZones(country);
if (countryTimeZones == null) {
return null;
}
final List<TimeZoneMapping> mappings = countryTimeZones.getTimeZoneMappings();
return extractTimeZoneIds(mappings);
}
private static List<String> extractTimeZoneIds(List<TimeZoneMapping> timeZoneMappings) {
final List<String> zoneIds = new ArrayList<>(timeZoneMappings.size());
for (TimeZoneMapping timeZoneMapping : timeZoneMappings) {
zoneIds.add(timeZoneMapping.timeZoneId);
}
return Collections.unmodifiableList(zoneIds);
}
}
}