diff options
author | Almaz Mingaleev <mingaleev@google.com> | 2021-03-30 08:33:37 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2021-03-30 08:33:37 +0000 |
commit | afd8455030f479105b0050f58510ff80e5b5b26a (patch) | |
tree | eb1163a159529235ba362a9b0957efc1c835d59f /android_icu4j | |
parent | 13855efd8a7d5e4de74f8a55e5083fb8d4d5a2bf (diff) | |
parent | c695c3758742aef86dbd3115d2ea6bbae4bbbfa1 (diff) | |
download | icu-afd8455030f479105b0050f58510ff80e5b5b26a.tar.gz |
Merge "Add TimeZoneMapping#isShownInPickerAfter method."
Diffstat (limited to 'android_icu4j')
3 files changed, 34 insertions, 5 deletions
diff --git a/android_icu4j/api/legacy_platform/current.txt b/android_icu4j/api/legacy_platform/current.txt index 6bdef6153..17cb11a81 100644 --- a/android_icu4j/api/legacy_platform/current.txt +++ b/android_icu4j/api/legacy_platform/current.txt @@ -75,10 +75,10 @@ package com.android.i18n.timezone { public static final class CountryTimeZones.TimeZoneMapping { method public static com.android.i18n.timezone.CountryTimeZones.TimeZoneMapping createForTests(String, boolean, Long, java.util.List<java.lang.String>); method public java.util.List<java.lang.String> getAlternativeIds(); - method public Long getNotUsedAfter(); method public android.icu.util.TimeZone getTimeZone(); method public String getTimeZoneId(); method public boolean isShownInPicker(); + method public boolean isShownInPickerAt(java.time.Instant); } public final class CountryZonesFinder { diff --git a/android_icu4j/libcore_bridge/src/java/com/android/i18n/timezone/CountryTimeZones.java b/android_icu4j/libcore_bridge/src/java/com/android/i18n/timezone/CountryTimeZones.java index ed72e27d2..8e937db68 100644 --- a/android_icu4j/libcore_bridge/src/java/com/android/i18n/timezone/CountryTimeZones.java +++ b/android_icu4j/libcore_bridge/src/java/com/android/i18n/timezone/CountryTimeZones.java @@ -20,6 +20,7 @@ import android.icu.util.TimeZone; import com.android.i18n.util.Log; +import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -70,8 +71,9 @@ public final class CountryTimeZones { } @libcore.api.CorePlatformApi - public Long getNotUsedAfter() { - return notUsedAfter; + public boolean isShownInPickerAt(Instant date) { + return isShownInPicker() + && (notUsedAfter == null || notUsedAfter >= date.toEpochMilli()); } /** diff --git a/android_icu4j/testing/src/com/android/i18n/test/timezone/CountryTimeZonesTest.java b/android_icu4j/testing/src/com/android/i18n/test/timezone/CountryTimeZonesTest.java index 7d78f9318..80471a7a9 100644 --- a/android_icu4j/testing/src/com/android/i18n/test/timezone/CountryTimeZonesTest.java +++ b/android_icu4j/testing/src/com/android/i18n/test/timezone/CountryTimeZonesTest.java @@ -21,9 +21,9 @@ import org.junit.Test; import android.icu.testsharding.MainTestShard; import android.icu.util.TimeZone; +import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.function.Function; @@ -32,7 +32,6 @@ import com.android.i18n.timezone.CountryTimeZones; import com.android.i18n.timezone.CountryTimeZones.OffsetResult; import com.android.i18n.timezone.CountryTimeZones.TimeZoneMapping; -import static java.util.Collections.emptyList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; @@ -500,6 +499,34 @@ public class CountryTimeZonesTest { assertEquals("Europe/London", timeZone.getID()); } + @Test + public void timeZoneMapping_isShownInPickerAfter_notHidden() { + long notUsedAfter = 1234; + TimeZoneMapping timeZoneMapping = + TimeZoneMapping.createForTests( + "Europe/London", true /* showInPicker */, notUsedAfter, list()); + + assertTrue(timeZoneMapping.isShownInPickerAt( + Instant.ofEpochMilli(notUsedAfter - 1_000))); + assertTrue(timeZoneMapping.isShownInPickerAt(Instant.ofEpochMilli(notUsedAfter))); + assertFalse(timeZoneMapping.isShownInPickerAt( + Instant.ofEpochMilli(notUsedAfter + 1_000))); + } + + @Test + public void timeZoneMapping_isShownInPickerAfter_hiddenTimeZone() { + long notUsedAfter = 1234; + TimeZoneMapping hiddenTimeZoneMapping = + TimeZoneMapping.createForTests( + "Moon/Secret_base", false /* showInPicker */, notUsedAfter, list()); + + assertFalse(hiddenTimeZoneMapping.isShownInPickerAt( + Instant.ofEpochMilli(notUsedAfter - 1_000))); + assertFalse(hiddenTimeZoneMapping.isShownInPickerAt(Instant.ofEpochMilli(notUsedAfter))); + assertFalse(hiddenTimeZoneMapping.isShownInPickerAt( + Instant.ofEpochMilli(notUsedAfter + 1_000))); + } + private void assertImmutableTimeZone(TimeZone timeZone) { try { timeZone.setRawOffset(1000); |