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

Commit 936374e5 authored by Neil Fuller's avatar Neil Fuller Committed by Gerrit Code Review
Browse files

Merge "Alter IDs considered in TimeZoneLookupHelper"

parents 28bbc318 0e28ff06
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -259,7 +259,11 @@ public final class TimeZoneLookupHelper {
    private static OffsetResult lookupByInstantOffsetDst(long timeMillis, int utcOffsetMillis,
            @Nullable Boolean isDst) {

        String[] zones = TimeZone.getAvailableIDs();
        // Use java.util.TimeZone and not android.icu.util.TimeZone to find candidate zone IDs: ICU
        // references some non-standard zone IDs that can be rejected by java.util.TimeZone. There
        // is a CTS test (in com.android.i18n.test.timezone.TimeZoneIntegrationTest) that confirms
        // that ICU can interpret all IDs that are known to java.util.TimeZone.
        String[] zones = java.util.TimeZone.getAvailableIDs();
        TimeZone match = null;
        boolean isOnlyMatch = true;
        for (String zone : zones) {
+15 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static com.android.internal.telephony.nitz.TimeZoneLookupHelper.CountryRe

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

@@ -37,8 +38,10 @@ import com.android.internal.telephony.nitz.TimeZoneLookupHelper.CountryResult;
import org.junit.Before;
import org.junit.Test;

import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;

public class TimeZoneLookupHelperTest {
@@ -447,6 +450,18 @@ public class TimeZoneLookupHelperTest {
        assertTrue(mTimeZoneLookupHelper.countryUsesUtc("gb", NH_WINTER_TIME_MILLIS));
    }

    @Test
    public void regressionTest_Bug167653885() {
        // This NITZ caused an error in Android R because lookupByNitz was returning a time zone
        // known to android.icu.util.TimeZone but not java.util.TimeZone.
        NitzData nitzData = NitzData.parse("20/05/08,04:15:48+08,00");
        OffsetResult offsetResult = mTimeZoneLookupHelper.lookupByNitz(nitzData);
        assertNotNull(offsetResult);

        List<String> knownIds = Arrays.asList(java.util.TimeZone.getAvailableIDs());
        assertTrue(knownIds.contains(offsetResult.getTimeZone().getID()));
    }

    /**
     * Assert the time zone in the OffsetResult has the expected properties at the specified time.
     */