102 * the local time.
103 * <p>
104 * For example, consider adding a period of one day and a duration of one day to
105 * 18:00 on the evening before a daylight savings gap. The {@code Period} will add
106 * the conceptual day and result in a {@code ZonedDateTime} at 18:00 the following day.
107 * By contrast, the {@code Duration} will add exactly 24 hours, resulting in a
108 * {@code ZonedDateTime} at 19:00 the following day (assuming a one hour DST gap).
109 * <p>
110 * The supported units of a period are {@link ChronoUnit#YEARS YEARS},
111 * {@link ChronoUnit#MONTHS MONTHS} and {@link ChronoUnit#DAYS DAYS}.
112 * All three fields are always present, but may be set to zero.
113 * <p>
114 * The ISO-8601 calendar system is the modern civil calendar system used today
115 * in most of the world. It is equivalent to the proleptic Gregorian calendar
116 * system, in which today's rules for leap years are applied for all time.
117 * <p>
118 * The period is modeled as a directed amount of time, meaning that individual parts of the
119 * period may be negative.
120 * <p>
121 * This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>
122 * class; programmers should treat instances that are
123 * {@linkplain #equals(Object) equal} as interchangeable and should not
124 * use instances for synchronization, or unpredictable behavior may
125 * occur. For example, in a future release, synchronization may fail.
126 * The {@code equals} method should be used for comparisons.
127 *
128 * @implSpec
129 * This class is immutable and thread-safe.
130 *
131 * @since 1.8
132 */
133 @jdk.internal.ValueBased
134 public final class Period
135 implements ChronoPeriod, Serializable {
136
137 /**
138 * A constant for a period of zero.
139 */
140 public static final Period ZERO = new Period(0, 0, 0);
141 /**
142 * Serialization version.
143 */
144 @java.io.Serial
145 private static final long serialVersionUID = -3587258372562876L;
146 /**
147 * The pattern for parsing.
148 */
149 private static final Pattern PATTERN =
150 Pattern.compile("([-+]?)P(?:([-+]?[0-9]+)Y)?(?:([-+]?[0-9]+)M)?(?:([-+]?[0-9]+)W)?(?:([-+]?[0-9]+)D)?", Pattern.CASE_INSENSITIVE);
151
152 /**
153 * The set of supported units.
|
102 * the local time.
103 * <p>
104 * For example, consider adding a period of one day and a duration of one day to
105 * 18:00 on the evening before a daylight savings gap. The {@code Period} will add
106 * the conceptual day and result in a {@code ZonedDateTime} at 18:00 the following day.
107 * By contrast, the {@code Duration} will add exactly 24 hours, resulting in a
108 * {@code ZonedDateTime} at 19:00 the following day (assuming a one hour DST gap).
109 * <p>
110 * The supported units of a period are {@link ChronoUnit#YEARS YEARS},
111 * {@link ChronoUnit#MONTHS MONTHS} and {@link ChronoUnit#DAYS DAYS}.
112 * All three fields are always present, but may be set to zero.
113 * <p>
114 * The ISO-8601 calendar system is the modern civil calendar system used today
115 * in most of the world. It is equivalent to the proleptic Gregorian calendar
116 * system, in which today's rules for leap years are applied for all time.
117 * <p>
118 * The period is modeled as a directed amount of time, meaning that individual parts of the
119 * period may be negative.
120 * <p>
121 * This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>
122 * class; programmers should treat instances that are {@linkplain #equals(Object) equal}
123 * as interchangeable and should not use instances for synchronization, mutexes, or
124 * with {@linkplain java.lang.ref.Reference object references}.
125 *
126 * <div class="preview-block">
127 * <div class="preview-comment">
128 * When preview features are enabled, {@code Period} is a {@linkplain Class#isValue value class}.
129 * Use of value class instances for synchronization, mutexes, or with
130 * {@linkplain java.lang.ref.Reference object references} result in
131 * {@link IdentityException}.
132 * </div>
133 * </div>
134 *
135 * @implSpec
136 * This class is immutable and thread-safe.
137 *
138 * @since 1.8
139 */
140 @jdk.internal.ValueBased
141 @jdk.internal.MigratedValueClass
142 public final class Period
143 implements ChronoPeriod, Serializable {
144
145 /**
146 * A constant for a period of zero.
147 */
148 public static final Period ZERO = new Period(0, 0, 0);
149 /**
150 * Serialization version.
151 */
152 @java.io.Serial
153 private static final long serialVersionUID = -3587258372562876L;
154 /**
155 * The pattern for parsing.
156 */
157 private static final Pattern PATTERN =
158 Pattern.compile("([-+]?)P(?:([-+]?[0-9]+)Y)?(?:([-+]?[0-9]+)M)?(?:([-+]?[0-9]+)W)?(?:([-+]?[0-9]+)D)?", Pattern.CASE_INSENSITIVE);
159
160 /**
161 * The set of supported units.
|