< prev index next >

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

Print this page

 96  * This class does not store or represent a year, time or time-zone.
 97  * For example, the value "December 3rd" can be stored in a {@code MonthDay}.
 98  * <p>
 99  * Since a {@code MonthDay} does not possess a year, the leap day of
100  * February 29th is considered valid.
101  * <p>
102  * This class implements {@link TemporalAccessor} rather than {@link Temporal}.
103  * This is because it is not possible to define whether February 29th is valid or not
104  * without external information, preventing the implementation of plus/minus.
105  * Related to this, {@code MonthDay} only provides access to query and set the fields
106  * {@code MONTH_OF_YEAR} and {@code DAY_OF_MONTH}.
107  * <p>
108  * The ISO-8601 calendar system is the modern civil calendar system used today
109  * in most of the world. It is equivalent to the proleptic Gregorian calendar
110  * system, in which today's rules for leap years are applied for all time.
111  * For most applications written today, the ISO-8601 rules are entirely suitable.
112  * However, any application that makes use of historical dates, and requires them
113  * to be accurate will find the ISO-8601 approach unsuitable.
114  * <p>
115  * This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>
116  * class; programmers should treat instances that are
117  * {@linkplain #equals(Object) equal} as interchangeable and should not
118  * use instances for synchronization, or unpredictable behavior may
119  * occur. For example, in a future release, synchronization may fail.
120  * The {@code equals} method should be used for comparisons.







121  *
122  * @implSpec
123  * This class is immutable and thread-safe.
124  *
125  * @since 1.8
126  */
127 @jdk.internal.ValueBased

128 public final class MonthDay
129         implements TemporalAccessor, TemporalAdjuster, Comparable<MonthDay>, Serializable {
130 
131     /**
132      * Serialization version.
133      */
134     @java.io.Serial
135     private static final long serialVersionUID = -939150713474957432L;
136     /**
137      * Parser.
138      */
139     private static final DateTimeFormatter PARSER = new DateTimeFormatterBuilder()
140         .appendLiteral("--")
141         .appendValue(MONTH_OF_YEAR, 2)
142         .appendLiteral('-')
143         .appendValue(DAY_OF_MONTH, 2)
144         .toFormatter();
145 
146     /**
147      * The month-of-year, not null.

 96  * This class does not store or represent a year, time or time-zone.
 97  * For example, the value "December 3rd" can be stored in a {@code MonthDay}.
 98  * <p>
 99  * Since a {@code MonthDay} does not possess a year, the leap day of
100  * February 29th is considered valid.
101  * <p>
102  * This class implements {@link TemporalAccessor} rather than {@link Temporal}.
103  * This is because it is not possible to define whether February 29th is valid or not
104  * without external information, preventing the implementation of plus/minus.
105  * Related to this, {@code MonthDay} only provides access to query and set the fields
106  * {@code MONTH_OF_YEAR} and {@code DAY_OF_MONTH}.
107  * <p>
108  * The ISO-8601 calendar system is the modern civil calendar system used today
109  * in most of the world. It is equivalent to the proleptic Gregorian calendar
110  * system, in which today's rules for leap years are applied for all time.
111  * For most applications written today, the ISO-8601 rules are entirely suitable.
112  * However, any application that makes use of historical dates, and requires them
113  * to be accurate will find the ISO-8601 approach unsuitable.
114  * <p>
115  * This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>
116  * class; programmers should treat instances that are {@linkplain #equals(Object) equal}
117  * as interchangeable and should not use instances for synchronization, mutexes, or
118  * with {@linkplain java.lang.ref.Reference object references}.
119  *
120  * <div class="preview-block">
121  *      <div class="preview-comment">
122  *          When preview features are enabled, {@code MonthDay} is a {@linkplain Class#isValue value class}.
123  *          Use of value class instances for synchronization, mutexes, or with
124  *          {@linkplain java.lang.ref.Reference object references} result in
125  *          {@link IdentityException}.
126  *      </div>
127  * </div>
128  *
129  * @implSpec
130  * This class is immutable and thread-safe.
131  *
132  * @since 1.8
133  */
134 @jdk.internal.ValueBased
135 @jdk.internal.MigratedValueClass
136 public final class MonthDay
137         implements TemporalAccessor, TemporalAdjuster, Comparable<MonthDay>, Serializable {
138 
139     /**
140      * Serialization version.
141      */
142     @java.io.Serial
143     private static final long serialVersionUID = -939150713474957432L;
144     /**
145      * Parser.
146      */
147     private static final DateTimeFormatter PARSER = new DateTimeFormatterBuilder()
148         .appendLiteral("--")
149         .appendValue(MONTH_OF_YEAR, 2)
150         .appendLiteral('-')
151         .appendValue(DAY_OF_MONTH, 2)
152         .toFormatter();
153 
154     /**
155      * The month-of-year, not null.
< prev index next >