< prev index next >

src/java.base/share/classes/java/time/ZoneId.java

Print this page

145  * region IDs are typically the same as the three letter airport code.
146  * However, the airport of Utrecht has the code 'UTC', which is obviously a conflict.
147  * The recommended format for region IDs from groups other than TZDB is 'group~region'.
148  * Thus if IATA data were defined, Utrecht airport would be 'IATA~UTC'.
149  *
150  * <h2>Serialization</h2>
151  * This class can be serialized and stores the string zone ID in the external form.
152  * The {@code ZoneOffset} subclass uses a dedicated format that only stores the
153  * offset from UTC/Greenwich.
154  * <p>
155  * A {@code ZoneId} can be deserialized in a Java Runtime where the ID is unknown.
156  * For example, if a server-side Java Runtime has been updated with a new zone ID, but
157  * the client-side Java Runtime has not been updated. In this case, the {@code ZoneId}
158  * object will exist, and can be queried using {@code getId}, {@code equals},
159  * {@code hashCode}, {@code toString}, {@code getDisplayName} and {@code normalized}.
160  * However, any call to {@code getRules} will fail with {@code ZoneRulesException}.
161  * This approach is designed to allow a {@link ZonedDateTime} to be loaded and
162  * queried, but not modified, on a Java Runtime with incomplete time-zone information.
163  * <p>
164  * This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>
165  * class; programmers should treat instances that are
166  * {@linkplain #equals(Object) equal} as interchangeable and should not
167  * use instances for synchronization, or unpredictable behavior may
168  * occur. For example, in a future release, synchronization may fail.
169  * The {@code equals} method should be used for comparisons.
170  *
171  * @implSpec
172  * This abstract sealed class permits two implementations, both of which are immutable and
173  * thread-safe. One implementation models region-based IDs, the other is {@code ZoneOffset}
174  * modelling offset-based IDs. This difference is visible in serialization.
175  *
176  * @since 1.8
177  * @sealedGraph
178  */
179 @jdk.internal.ValueBased
180 public abstract sealed class ZoneId implements Serializable permits ZoneOffset, ZoneRegion {
181 
182     /**
183      * A map of zone overrides to enable the short time-zone names to be used.
184      * <p>
185      * Use of short zone IDs has been deprecated in {@code java.util.TimeZone}.
186      * This map allows the IDs to continue to be used via the
187      * {@link #of(String, Map)} factory method.
188      * <p>
189      * This map contains a mapping of the IDs that is in line with TZDB 2024b and

145  * region IDs are typically the same as the three letter airport code.
146  * However, the airport of Utrecht has the code 'UTC', which is obviously a conflict.
147  * The recommended format for region IDs from groups other than TZDB is 'group~region'.
148  * Thus if IATA data were defined, Utrecht airport would be 'IATA~UTC'.
149  *
150  * <h2>Serialization</h2>
151  * This class can be serialized and stores the string zone ID in the external form.
152  * The {@code ZoneOffset} subclass uses a dedicated format that only stores the
153  * offset from UTC/Greenwich.
154  * <p>
155  * A {@code ZoneId} can be deserialized in a Java Runtime where the ID is unknown.
156  * For example, if a server-side Java Runtime has been updated with a new zone ID, but
157  * the client-side Java Runtime has not been updated. In this case, the {@code ZoneId}
158  * object will exist, and can be queried using {@code getId}, {@code equals},
159  * {@code hashCode}, {@code toString}, {@code getDisplayName} and {@code normalized}.
160  * However, any call to {@code getRules} will fail with {@code ZoneRulesException}.
161  * This approach is designed to allow a {@link ZonedDateTime} to be loaded and
162  * queried, but not modified, on a Java Runtime with incomplete time-zone information.
163  * <p>
164  * This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>
165  * class; programmers should treat instances that are {@linkplain #equals(Object) equal}
166  * as interchangeable and should not use instances for synchronization, mutexes, or
167  * with {@linkplain java.lang.ref.Reference object references}.


168  *
169  * @implSpec
170  * This abstract sealed class permits two implementations, both of which are immutable and
171  * thread-safe. One implementation models region-based IDs, the other is {@code ZoneOffset}
172  * modelling offset-based IDs. This difference is visible in serialization.
173  *
174  * @since 1.8
175  * @sealedGraph
176  */
177 @jdk.internal.ValueBased
178 public abstract sealed class ZoneId implements Serializable permits ZoneOffset, ZoneRegion {
179 
180     /**
181      * A map of zone overrides to enable the short time-zone names to be used.
182      * <p>
183      * Use of short zone IDs has been deprecated in {@code java.util.TimeZone}.
184      * This map allows the IDs to continue to be used via the
185      * {@link #of(String, Map)} factory method.
186      * <p>
187      * This map contains a mapping of the IDs that is in line with TZDB 2024b and
< prev index next >