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

Commit 21316e0b authored by Neil Fuller's avatar Neil Fuller
Browse files

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: I6c8b791524d16223c414612913b22f4d70c27d61
Merged-In: I6c8b791524d16223c414612913b22f4d70c27d61
(cherry picked from commit 400efa36)
parent 036ea39d
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -62,9 +62,9 @@ public class TimeUtils {
    }

    /**
     * Tries to return a frozen ICU time zone that would have had the specified offset
     * and DST value at the specified moment in the specified country.
     * Returns null if no suitable zone could be found.
     * Returns a frozen ICU time zone that has / would have had the specified offset and DST value
     * at the specified moment in the specified country. Returns null if no suitable zone could be
     * found.
     */
    private static android.icu.util.TimeZone getIcuTimeZone(
            int offset, boolean dst, long when, String country) {
@@ -73,8 +73,15 @@ public class TimeUtils {
        }

        android.icu.util.TimeZone bias = android.icu.util.TimeZone.getDefault();
        return TimeZoneFinder.getInstance()
                .lookupTimeZoneByCountryAndOffset(country, offset, dst, when, bias);
        CountryTimeZones countryTimeZones =
                TimeZoneFinder.getInstance().lookupCountryTimeZones(country);
        if (countryTimeZones == null) {
            return null;
        }

        CountryTimeZones.OffsetResult offsetResult =
                countryTimeZones.lookupByOffsetWithBias(offset, dst, when, bias);
        return offsetResult != null ? offsetResult.mTimeZone : null;
    }

    /**