< prev index next >

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

Print this page

 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.

 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 @jdk.internal.MigratedValueClass
 135 public final class Period
 136         implements ChronoPeriod, Serializable {
 137 
 138     /**
 139      * A constant for a period of zero.
 140      */
 141     public static final Period ZERO = new Period(0, 0, 0);
 142     /**
 143      * Serialization version.
 144      */
 145     @java.io.Serial
 146     private static final long serialVersionUID = -3587258372562876L;
 147     /**
 148      * The pattern for parsing.
 149      */
 150     private static final Pattern PATTERN =
 151             Pattern.compile("([-+]?)P(?:([-+]?[0-9]+)Y)?(?:([-+]?[0-9]+)M)?(?:([-+]?[0-9]+)W)?(?:([-+]?[0-9]+)D)?", Pattern.CASE_INSENSITIVE);
 152 
 153     /**
 154      * The set of supported units.
< prev index next >