Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4492ec57 authored by Neil Fuller's avatar Neil Fuller Committed by Gerrit Code Review
Browse files

Merge "API for retrieving time zone IDs by country"

parents 3d2b099d 6caa954e
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -46255,6 +46255,7 @@ package android.util {
  public class TimeUtils {
  public class TimeUtils {
    method public static java.util.TimeZone getTimeZone(int, boolean, long, java.lang.String);
    method public static java.util.TimeZone getTimeZone(int, boolean, long, java.lang.String);
    method public static java.lang.String getTimeZoneDatabaseVersion();
    method public static java.lang.String getTimeZoneDatabaseVersion();
    method public static java.util.List<java.lang.String> getTimeZoneIdsForCountryCode(java.lang.String);
  }
  }
  public class TimingLogger {
  public class TimingLogger {
+40 −0
Original line number Original line Diff line number Diff line
@@ -16,16 +16,24 @@


package android.util;
package android.util;


import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UnsupportedAppUsage;
import android.annotation.UnsupportedAppUsage;
import android.os.SystemClock;
import android.os.SystemClock;


import libcore.util.CountryTimeZones;
import libcore.util.CountryTimeZones.TimeZoneMapping;
import libcore.util.TimeZoneFinder;
import libcore.util.TimeZoneFinder;
import libcore.util.ZoneInfoDB;
import libcore.util.ZoneInfoDB;


import java.io.PrintWriter;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.Date;
import java.util.List;

/**
/**
 * A class containing utility methods related to time zones.
 * A class containing utility methods related to time zones.
 */
 */
@@ -64,6 +72,38 @@ public class TimeUtils {
                .lookupTimeZoneByCountryAndOffset(country, offset, dst, when, bias);
                .lookupTimeZoneByCountryAndOffset(country, offset, dst, when, bias);
    }
    }


    /**
     * Returns time zone IDs for time zones known to be associated with a country.
     *
     * <p>The list returned may be different from other on-device sources like
     * {@link android.icu.util.TimeZone#getRegion(String)} as it can be curated to avoid
     * contentious mappings.
     *
     * @param countryCode the ISO 3166-1 alpha-2 code for the country as can be obtained using
     *     {@link java.util.Locale#getCountry()}
     * @return IDs that can be passed to {@link java.util.TimeZone#getTimeZone(String)} or similar
     *     methods, or {@code null} if the countryCode is unrecognized
     */
    public static @Nullable List<String> getTimeZoneIdsForCountryCode(@NonNull String countryCode) {
        if (countryCode == null) {
            throw new NullPointerException("countryCode == null");
        }
        TimeZoneFinder timeZoneFinder = TimeZoneFinder.getInstance();
        CountryTimeZones countryTimeZones =
                timeZoneFinder.lookupCountryTimeZones(countryCode.toLowerCase());
        if (countryTimeZones == null) {
            return null;
        }

        List<String> timeZoneIds = new ArrayList<>();
        for (TimeZoneMapping timeZoneMapping : countryTimeZones.getTimeZoneMappings()) {
            if (timeZoneMapping.showInPicker) {
                timeZoneIds.add(timeZoneMapping.timeZoneId);
            }
        }
        return Collections.unmodifiableList(timeZoneIds);
    }

    /**
    /**
     * Returns a String indicating the version of the time zone database currently
     * Returns a String indicating the version of the time zone database currently
     * in use.  The format of the string is dependent on the underlying time zone
     * in use.  The format of the string is dependent on the underlying time zone