1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.timezone; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 22 import com.android.internal.annotations.GuardedBy; 23 24 import java.util.Objects; 25 26 /** 27 * A class that can be used to find time zones using information like country and offset. 28 * 29 * @hide 30 */ 31 public final class TimeZoneFinder { 32 33 private static final Object sLock = new Object(); 34 @GuardedBy("sLock") 35 private static TimeZoneFinder sInstance; 36 37 /** 38 * Obtains the singleton instance. 39 */ 40 @NonNull getInstance()41 public static TimeZoneFinder getInstance() { 42 synchronized (sLock) { 43 if (sInstance == null) { 44 sInstance = new TimeZoneFinder(libcore.timezone.TimeZoneFinder.getInstance()); 45 } 46 } 47 return sInstance; 48 } 49 50 @NonNull 51 private final libcore.timezone.TimeZoneFinder mDelegate; 52 TimeZoneFinder(@onNull libcore.timezone.TimeZoneFinder delegate)53 private TimeZoneFinder(@NonNull libcore.timezone.TimeZoneFinder delegate) { 54 mDelegate = Objects.requireNonNull(delegate); 55 } 56 57 /** 58 * Returns the IANA rules version associated with the data. If there is no version information 59 * or there is a problem reading the file then {@code null} is returned. 60 */ 61 @Nullable getIanaVersion()62 public String getIanaVersion() { 63 return mDelegate.getIanaVersion(); 64 } 65 66 /** 67 * Returns a {@link CountryTimeZones} object associated with the specified country code. 68 * Caching is handled as needed. If the country code is not recognized or there is an error 69 * during lookup this method can return null. 70 */ 71 @Nullable lookupCountryTimeZones(@onNull String countryIso)72 public CountryTimeZones lookupCountryTimeZones(@NonNull String countryIso) { 73 libcore.timezone.CountryTimeZones delegate = mDelegate.lookupCountryTimeZones(countryIso); 74 return delegate == null ? null : new CountryTimeZones(delegate); 75 } 76 } 77