getCache static method
Creates a provider backed by the given DateTimeZoneSource.
Note that the source will never be consulted for requests for the fixed-offset timezones 'UTC' and 'UTC+/-Offset' (a standard implementation will be returned instead). This is true even if these IDs are advertised by the source.
source: The DateTimeZoneSource for this provider.
InvalidDateTimeZoneSourceException: source violates its contract.
Implementation
static Future<DateTimeZoneCache> getCache(DateTimeZoneSource source) async {
Preconditions.checkNotNull(source, 'source');
var providerIds = await source.getIds();
if (providerIds == null) {
throw InvalidDateTimeZoneSourceError(
'Source-returned ID sequence was null');
}
var idList = List<String>.from(providerIds);
// todo: a gentler 'null' okay sorter?
// idList.sort((a, b) => (a ?? '').compareTo(b ?? '')); // sort(StringComparer.Ordinal);
idList.sort();
var ids = List<String>.from(idList);
var cache = DateTimeZoneCache._(source, ids);
// Populate the dictionary with null values meaning "the ID is valid, we haven't fetched the zone yet".
for (String id in ids) {
cache._timeZoneMap[id] = null;
}
return cache;
}