8347955: TimeZone methods to stream the available timezone IDs

Reviewed-by: naoto, rriggs
This commit is contained in:
Justin Lu 2025-01-28 21:31:46 +00:00
parent 1efae9a41e
commit 3a564ed101
16 changed files with 177 additions and 34 deletions

View file

@ -41,6 +41,7 @@ package java.util;
import java.io.Serializable;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.stream.Stream;
import jdk.internal.util.StaticProperty;
import sun.util.calendar.ZoneInfo;
@ -615,24 +616,63 @@ public abstract class TimeZone implements Serializable, Cloneable {
/**
* Gets the available IDs according to the given time zone offset in milliseconds.
*
* @apiNote Consider using {@link #availableIDs(int)} which returns
* a stream of the available time zone IDs according to the given offset.
*
* @param rawOffset the given time zone GMT offset in milliseconds.
* @return an array of IDs, where the time zone for that ID has
* the specified GMT offset. For example, "America/Phoenix" and "America/Denver"
* both have GMT-07:00, but differ in daylight saving behavior.
* @see #getRawOffset()
* @see #availableIDs(int)
*/
public static String[] getAvailableIDs(int rawOffset) {
return ZoneInfo.getAvailableIDs(rawOffset);
}
/**
* Gets all the available IDs supported.
* @return an array of IDs.
* {@return an array of the available IDs supported}
*
* @apiNote Consider using {@link #availableIDs()} which returns
* a stream of the available time zone IDs.
*
* @see #availableIDs()
*/
public static String[] getAvailableIDs() {
return ZoneInfo.getAvailableIDs();
}
/**
* Gets the available IDs according to the given time zone offset in milliseconds.
*
* @implNote Unlike {@link #getAvailableIDs(int)}, this method does
* not create a copy of the {@code TimeZone} IDs array.
*
* @param rawOffset the given time zone GMT offset in milliseconds.
* @return a stream of IDs, where the time zone for that ID has
* the specified GMT offset. For example, "America/Phoenix" and "America/Denver"
* both have GMT-07:00, but differ in daylight saving behavior.
* @see #getRawOffset()
* @see #getAvailableIDs(int)
* @since 25
*/
public static Stream<String> availableIDs(int rawOffset) {
return ZoneInfo.availableIDs(rawOffset);
}
/**
* {@return a stream of the available IDs supported}
*
* @implNote Unlike {@link #getAvailableIDs()}, this method does
* not create a copy of the {@code TimeZone} IDs array.
*
* @since 25
* @see #getAvailableIDs()
*/
public static Stream<String> availableIDs() {
return ZoneInfo.availableIDs();
}
/**
* Gets the platform defined TimeZone ID.
**/