blob: 9327b001a9c8406dbd026cae4256a0a03edeba96 [file] [log] [blame]
Neil Fullerf7346ec2019-08-30 18:02:47 +01001/*
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
17package android.timezone;
18
19import android.annotation.NonNull;
20import android.annotation.Nullable;
21import android.annotation.SystemApi;
22
23import com.android.internal.annotations.GuardedBy;
24
Neil Fuller2551c032020-01-16 18:39:17 +000025import java.util.Objects;
26
Neil Fullerf7346ec2019-08-30 18:02:47 +010027/**
Neil Fuller2551c032020-01-16 18:39:17 +000028 * A class that can be used to find time zones using information like country and offset.
Neil Fullerf7346ec2019-08-30 18:02:47 +010029 *
30 * @hide
31 */
32@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
33public final class TimeZoneFinder {
34
35 private static Object sLock = new Object();
36 @GuardedBy("sLock")
37 private static TimeZoneFinder sInstance;
38
Neil Fullerf7346ec2019-08-30 18:02:47 +010039 /**
Neil Fuller2551c032020-01-16 18:39:17 +000040 * Obtains the singleton instance.
Neil Fullerf7346ec2019-08-30 18:02:47 +010041 */
42 @NonNull
43 public static TimeZoneFinder getInstance() {
44 synchronized (sLock) {
45 if (sInstance == null) {
46 sInstance = new TimeZoneFinder(libcore.timezone.TimeZoneFinder.getInstance());
47 }
48 }
49 return sInstance;
50 }
51
Neil Fuller2551c032020-01-16 18:39:17 +000052 @NonNull
53 private final libcore.timezone.TimeZoneFinder mDelegate;
54
55 private TimeZoneFinder(@NonNull libcore.timezone.TimeZoneFinder delegate) {
56 mDelegate = Objects.requireNonNull(delegate);
57 }
58
59 /**
60 * Returns the IANA rules version associated with the data. If there is no version information
61 * or there is a problem reading the file then {@code null} is returned.
62 */
63 @Nullable
64 public String getIanaVersion() {
65 return mDelegate.getIanaVersion();
66 }
67
Neil Fullerf7346ec2019-08-30 18:02:47 +010068 /**
69 * Returns a {@link CountryTimeZones} object associated with the specified country code.
70 * Caching is handled as needed. If the country code is not recognized or there is an error
71 * during lookup this method can return null.
72 */
73 @Nullable
74 public CountryTimeZones lookupCountryTimeZones(@NonNull String countryIso) {
75 libcore.timezone.CountryTimeZones delegate = mDelegate.lookupCountryTimeZones(countryIso);
76 return delegate == null ? null : new CountryTimeZones(delegate);
77 }
78}