• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 /*
27  * This file is available under and governed by the GNU General Public
28  * License version 2 only, as published by the Free Software Foundation.
29  * However, the following notice accompanied the original version of this
30  * file:
31  *
32  * Copyright (c) 2007-2012, Stephen Colebourne & Michael Nascimento Santos
33  *
34  * All rights reserved.
35  *
36  * Redistribution and use in source and binary forms, with or without
37  * modification, are permitted provided that the following conditions are met:
38  *
39  *  * Redistributions of source code must retain the above copyright notice,
40  *    this list of conditions and the following disclaimer.
41  *
42  *  * Redistributions in binary form must reproduce the above copyright notice,
43  *    this list of conditions and the following disclaimer in the documentation
44  *    and/or other materials provided with the distribution.
45  *
46  *  * Neither the name of JSR-310 nor the names of its contributors
47  *    may be used to endorse or promote products derived from this software
48  *    without specific prior written permission.
49  *
50  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
54  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
55  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
56  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
57  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
58  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
59  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
60  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61  */
62 package java.time.chrono;
63 
64 import static java.time.temporal.ChronoField.EPOCH_DAY;
65 import static java.time.temporal.ChronoField.NANO_OF_DAY;
66 import static java.time.temporal.ChronoUnit.FOREVER;
67 import static java.time.temporal.ChronoUnit.NANOS;
68 
69 import java.time.DateTimeException;
70 import java.time.Instant;
71 import java.time.LocalDateTime;
72 import java.time.LocalTime;
73 import java.time.ZoneId;
74 import java.time.ZoneOffset;
75 import java.time.format.DateTimeFormatter;
76 import java.time.temporal.ChronoField;
77 import java.time.temporal.ChronoUnit;
78 import java.time.temporal.Temporal;
79 import java.time.temporal.TemporalAccessor;
80 import java.time.temporal.TemporalAdjuster;
81 import java.time.temporal.TemporalAmount;
82 import java.time.temporal.TemporalField;
83 import java.time.temporal.TemporalQueries;
84 import java.time.temporal.TemporalQuery;
85 import java.time.temporal.TemporalUnit;
86 import java.time.zone.ZoneRules;
87 import java.util.Comparator;
88 import java.util.Objects;
89 
90 /**
91  * A date-time without a time-zone in an arbitrary chronology, intended
92  * for advanced globalization use cases.
93  * <p>
94  * <b>Most applications should declare method signatures, fields and variables
95  * as {@link LocalDateTime}, not this interface.</b>
96  * <p>
97  * A {@code ChronoLocalDateTime} is the abstract representation of a local date-time
98  * where the {@code Chronology chronology}, or calendar system, is pluggable.
99  * The date-time is defined in terms of fields expressed by {@link TemporalField},
100  * where most common implementations are defined in {@link ChronoField}.
101  * The chronology defines how the calendar system operates and the meaning of
102  * the standard fields.
103  *
104  * <h3>When to use this interface</h3>
105  * The design of the API encourages the use of {@code LocalDateTime} rather than this
106  * interface, even in the case where the application needs to deal with multiple
107  * calendar systems. The rationale for this is explored in detail in {@link ChronoLocalDate}.
108  * <p>
109  * Ensure that the discussion in {@code ChronoLocalDate} has been read and understood
110  * before using this interface.
111  *
112  * @implSpec
113  * This interface must be implemented with care to ensure other classes operate correctly.
114  * All implementations that can be instantiated must be final, immutable and thread-safe.
115  * Subclasses should be Serializable wherever possible.
116  *
117  * @param <D> the concrete type for the date of this date-time
118  * @since 1.8
119  */
120 public interface ChronoLocalDateTime<D extends ChronoLocalDate>
121         extends Temporal, TemporalAdjuster, Comparable<ChronoLocalDateTime<?>> {
122 
123     /**
124      * Gets a comparator that compares {@code ChronoLocalDateTime} in
125      * time-line order ignoring the chronology.
126      * <p>
127      * This comparator differs from the comparison in {@link #compareTo} in that it
128      * only compares the underlying date-time and not the chronology.
129      * This allows dates in different calendar systems to be compared based
130      * on the position of the date-time on the local time-line.
131      * The underlying comparison is equivalent to comparing the epoch-day and nano-of-day.
132      *
133      * @return a comparator that compares in time-line order ignoring the chronology
134      * @see #isAfter
135      * @see #isBefore
136      * @see #isEqual
137      */
timeLineOrder()138     static Comparator<ChronoLocalDateTime<?>> timeLineOrder() {
139         return AbstractChronology.DATE_TIME_ORDER;
140     }
141 
142     //-----------------------------------------------------------------------
143     /**
144      * Obtains an instance of {@code ChronoLocalDateTime} from a temporal object.
145      * <p>
146      * This obtains a local date-time based on the specified temporal.
147      * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
148      * which this factory converts to an instance of {@code ChronoLocalDateTime}.
149      * <p>
150      * The conversion extracts and combines the chronology and the date-time
151      * from the temporal object. The behavior is equivalent to using
152      * {@link Chronology#localDateTime(TemporalAccessor)} with the extracted chronology.
153      * Implementations are permitted to perform optimizations such as accessing
154      * those fields that are equivalent to the relevant objects.
155      * <p>
156      * This method matches the signature of the functional interface {@link TemporalQuery}
157      * allowing it to be used as a query via method reference, {@code ChronoLocalDateTime::from}.
158      *
159      * @param temporal  the temporal object to convert, not null
160      * @return the date-time, not null
161      * @throws DateTimeException if unable to convert to a {@code ChronoLocalDateTime}
162      * @see Chronology#localDateTime(TemporalAccessor)
163      */
from(TemporalAccessor temporal)164     static ChronoLocalDateTime<?> from(TemporalAccessor temporal) {
165         if (temporal instanceof ChronoLocalDateTime) {
166             return (ChronoLocalDateTime<?>) temporal;
167         }
168         Objects.requireNonNull(temporal, "temporal");
169         Chronology chrono = temporal.query(TemporalQueries.chronology());
170         if (chrono == null) {
171             throw new DateTimeException("Unable to obtain ChronoLocalDateTime from TemporalAccessor: " + temporal.getClass());
172         }
173         return chrono.localDateTime(temporal);
174     }
175 
176     //-----------------------------------------------------------------------
177     /**
178      * Gets the chronology of this date-time.
179      * <p>
180      * The {@code Chronology} represents the calendar system in use.
181      * The era and other fields in {@link ChronoField} are defined by the chronology.
182      *
183      * @return the chronology, not null
184      */
getChronology()185     default Chronology getChronology() {
186         return toLocalDate().getChronology();
187     }
188 
189     /**
190      * Gets the local date part of this date-time.
191      * <p>
192      * This returns a local date with the same year, month and day
193      * as this date-time.
194      *
195      * @return the date part of this date-time, not null
196      */
toLocalDate()197     D toLocalDate() ;
198 
199     /**
200      * Gets the local time part of this date-time.
201      * <p>
202      * This returns a local time with the same hour, minute, second and
203      * nanosecond as this date-time.
204      *
205      * @return the time part of this date-time, not null
206      */
toLocalTime()207     LocalTime toLocalTime();
208 
209     /**
210      * Checks if the specified field is supported.
211      * <p>
212      * This checks if the specified field can be queried on this date-time.
213      * If false, then calling the {@link #range(TemporalField) range},
214      * {@link #get(TemporalField) get} and {@link #with(TemporalField, long)}
215      * methods will throw an exception.
216      * <p>
217      * The set of supported fields is defined by the chronology and normally includes
218      * all {@code ChronoField} date and time fields.
219      * <p>
220      * If the field is not a {@code ChronoField}, then the result of this method
221      * is obtained by invoking {@code TemporalField.isSupportedBy(TemporalAccessor)}
222      * passing {@code this} as the argument.
223      * Whether the field is supported is determined by the field.
224      *
225      * @param field  the field to check, null returns false
226      * @return true if the field can be queried, false if not
227      */
228     @Override
isSupported(TemporalField field)229     boolean isSupported(TemporalField field);
230 
231     /**
232      * Checks if the specified unit is supported.
233      * <p>
234      * This checks if the specified unit can be added to or subtracted from this date-time.
235      * If false, then calling the {@link #plus(long, TemporalUnit)} and
236      * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
237      * <p>
238      * The set of supported units is defined by the chronology and normally includes
239      * all {@code ChronoUnit} units except {@code FOREVER}.
240      * <p>
241      * If the unit is not a {@code ChronoUnit}, then the result of this method
242      * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
243      * passing {@code this} as the argument.
244      * Whether the unit is supported is determined by the unit.
245      *
246      * @param unit  the unit to check, null returns false
247      * @return true if the unit can be added/subtracted, false if not
248      */
249     @Override
isSupported(TemporalUnit unit)250     default boolean isSupported(TemporalUnit unit) {
251         if (unit instanceof ChronoUnit) {
252             return unit != FOREVER;
253         }
254         return unit != null && unit.isSupportedBy(this);
255     }
256 
257     //-----------------------------------------------------------------------
258     // override for covariant return type
259     /**
260      * {@inheritDoc}
261      * @throws DateTimeException {@inheritDoc}
262      * @throws ArithmeticException {@inheritDoc}
263      */
264     @Override
with(TemporalAdjuster adjuster)265     default ChronoLocalDateTime<D> with(TemporalAdjuster adjuster) {
266         return ChronoLocalDateTimeImpl.ensureValid(getChronology(), Temporal.super.with(adjuster));
267     }
268 
269     /**
270      * {@inheritDoc}
271      * @throws DateTimeException {@inheritDoc}
272      * @throws ArithmeticException {@inheritDoc}
273      */
274     @Override
with(TemporalField field, long newValue)275     ChronoLocalDateTime<D> with(TemporalField field, long newValue);
276 
277     /**
278      * {@inheritDoc}
279      * @throws DateTimeException {@inheritDoc}
280      * @throws ArithmeticException {@inheritDoc}
281      */
282     @Override
plus(TemporalAmount amount)283     default ChronoLocalDateTime<D> plus(TemporalAmount amount) {
284         return ChronoLocalDateTimeImpl.ensureValid(getChronology(), Temporal.super.plus(amount));
285     }
286 
287     /**
288      * {@inheritDoc}
289      * @throws DateTimeException {@inheritDoc}
290      * @throws ArithmeticException {@inheritDoc}
291      */
292     @Override
plus(long amountToAdd, TemporalUnit unit)293     ChronoLocalDateTime<D> plus(long amountToAdd, TemporalUnit unit);
294 
295     /**
296      * {@inheritDoc}
297      * @throws DateTimeException {@inheritDoc}
298      * @throws ArithmeticException {@inheritDoc}
299      */
300     @Override
minus(TemporalAmount amount)301     default ChronoLocalDateTime<D> minus(TemporalAmount amount) {
302         return ChronoLocalDateTimeImpl.ensureValid(getChronology(), Temporal.super.minus(amount));
303     }
304 
305     /**
306      * {@inheritDoc}
307      * @throws DateTimeException {@inheritDoc}
308      * @throws ArithmeticException {@inheritDoc}
309      */
310     @Override
minus(long amountToSubtract, TemporalUnit unit)311     default ChronoLocalDateTime<D> minus(long amountToSubtract, TemporalUnit unit) {
312         return ChronoLocalDateTimeImpl.ensureValid(getChronology(), Temporal.super.minus(amountToSubtract, unit));
313     }
314 
315     //-----------------------------------------------------------------------
316     /**
317      * Queries this date-time using the specified query.
318      * <p>
319      * This queries this date-time using the specified query strategy object.
320      * The {@code TemporalQuery} object defines the logic to be used to
321      * obtain the result. Read the documentation of the query to understand
322      * what the result of this method will be.
323      * <p>
324      * The result of this method is obtained by invoking the
325      * {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the
326      * specified query passing {@code this} as the argument.
327      *
328      * @param <R> the type of the result
329      * @param query  the query to invoke, not null
330      * @return the query result, null may be returned (defined by the query)
331      * @throws DateTimeException if unable to query (defined by the query)
332      * @throws ArithmeticException if numeric overflow occurs (defined by the query)
333      */
334     @SuppressWarnings("unchecked")
335     @Override
query(TemporalQuery<R> query)336     default <R> R query(TemporalQuery<R> query) {
337         if (query == TemporalQueries.zoneId() || query == TemporalQueries.zone() || query == TemporalQueries.offset()) {
338             return null;
339         } else if (query == TemporalQueries.localTime()) {
340             return (R) toLocalTime();
341         } else if (query == TemporalQueries.chronology()) {
342             return (R) getChronology();
343         } else if (query == TemporalQueries.precision()) {
344             return (R) NANOS;
345         }
346         // inline TemporalAccessor.super.query(query) as an optimization
347         // non-JDK classes are not permitted to make this optimization
348         return query.queryFrom(this);
349     }
350 
351     /**
352      * Adjusts the specified temporal object to have the same date and time as this object.
353      * <p>
354      * This returns a temporal object of the same observable type as the input
355      * with the date and time changed to be the same as this.
356      * <p>
357      * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
358      * twice, passing {@link ChronoField#EPOCH_DAY} and
359      * {@link ChronoField#NANO_OF_DAY} as the fields.
360      * <p>
361      * In most cases, it is clearer to reverse the calling pattern by using
362      * {@link Temporal#with(TemporalAdjuster)}:
363      * <pre>
364      *   // these two lines are equivalent, but the second approach is recommended
365      *   temporal = thisLocalDateTime.adjustInto(temporal);
366      *   temporal = temporal.with(thisLocalDateTime);
367      * </pre>
368      * <p>
369      * This instance is immutable and unaffected by this method call.
370      *
371      * @param temporal  the target object to be adjusted, not null
372      * @return the adjusted object, not null
373      * @throws DateTimeException if unable to make the adjustment
374      * @throws ArithmeticException if numeric overflow occurs
375      */
376     @Override
adjustInto(Temporal temporal)377     default Temporal adjustInto(Temporal temporal) {
378         return temporal
379                 .with(EPOCH_DAY, toLocalDate().toEpochDay())
380                 .with(NANO_OF_DAY, toLocalTime().toNanoOfDay());
381     }
382 
383     /**
384      * Formats this date-time using the specified formatter.
385      * <p>
386      * This date-time will be passed to the formatter to produce a string.
387      * <p>
388      * The default implementation must behave as follows:
389      * <pre>
390      *  return formatter.format(this);
391      * </pre>
392      *
393      * @param formatter  the formatter to use, not null
394      * @return the formatted date-time string, not null
395      * @throws DateTimeException if an error occurs during printing
396      */
format(DateTimeFormatter formatter)397     default String format(DateTimeFormatter formatter) {
398         Objects.requireNonNull(formatter, "formatter");
399         return formatter.format(this);
400     }
401 
402     //-----------------------------------------------------------------------
403     /**
404      * Combines this time with a time-zone to create a {@code ChronoZonedDateTime}.
405      * <p>
406      * This returns a {@code ChronoZonedDateTime} formed from this date-time at the
407      * specified time-zone. The result will match this date-time as closely as possible.
408      * Time-zone rules, such as daylight savings, mean that not every local date-time
409      * is valid for the specified zone, thus the local date-time may be adjusted.
410      * <p>
411      * The local date-time is resolved to a single instant on the time-line.
412      * This is achieved by finding a valid offset from UTC/Greenwich for the local
413      * date-time as defined by the {@link ZoneRules rules} of the zone ID.
414      *<p>
415      * In most cases, there is only one valid offset for a local date-time.
416      * In the case of an overlap, where clocks are set back, there are two valid offsets.
417      * This method uses the earlier offset typically corresponding to "summer".
418      * <p>
419      * In the case of a gap, where clocks jump forward, there is no valid offset.
420      * Instead, the local date-time is adjusted to be later by the length of the gap.
421      * For a typical one hour daylight savings change, the local date-time will be
422      * moved one hour later into the offset typically corresponding to "summer".
423      * <p>
424      * To obtain the later offset during an overlap, call
425      * {@link ChronoZonedDateTime#withLaterOffsetAtOverlap()} on the result of this method.
426      *
427      * @param zone  the time-zone to use, not null
428      * @return the zoned date-time formed from this date-time, not null
429      */
atZone(ZoneId zone)430     ChronoZonedDateTime<D> atZone(ZoneId zone);
431 
432     //-----------------------------------------------------------------------
433     /**
434      * Converts this date-time to an {@code Instant}.
435      * <p>
436      * This combines this local date-time and the specified offset to form
437      * an {@code Instant}.
438      * <p>
439      * This default implementation calculates from the epoch-day of the date and the
440      * second-of-day of the time.
441      *
442      * @param offset  the offset to use for the conversion, not null
443      * @return an {@code Instant} representing the same instant, not null
444      */
toInstant(ZoneOffset offset)445     default Instant toInstant(ZoneOffset offset) {
446         return Instant.ofEpochSecond(toEpochSecond(offset), toLocalTime().getNano());
447     }
448 
449     /**
450      * Converts this date-time to the number of seconds from the epoch
451      * of 1970-01-01T00:00:00Z.
452      * <p>
453      * This combines this local date-time and the specified offset to calculate the
454      * epoch-second value, which is the number of elapsed seconds from 1970-01-01T00:00:00Z.
455      * Instants on the time-line after the epoch are positive, earlier are negative.
456      * <p>
457      * This default implementation calculates from the epoch-day of the date and the
458      * second-of-day of the time.
459      *
460      * @param offset  the offset to use for the conversion, not null
461      * @return the number of seconds from the epoch of 1970-01-01T00:00:00Z
462      */
toEpochSecond(ZoneOffset offset)463     default long toEpochSecond(ZoneOffset offset) {
464         Objects.requireNonNull(offset, "offset");
465         long epochDay = toLocalDate().toEpochDay();
466         long secs = epochDay * 86400 + toLocalTime().toSecondOfDay();
467         secs -= offset.getTotalSeconds();
468         return secs;
469     }
470 
471     //-----------------------------------------------------------------------
472     /**
473      * Compares this date-time to another date-time, including the chronology.
474      * <p>
475      * The comparison is based first on the underlying time-line date-time, then
476      * on the chronology.
477      * It is "consistent with equals", as defined by {@link Comparable}.
478      * <p>
479      * For example, the following is the comparator order:
480      * <ol>
481      * <li>{@code 2012-12-03T12:00 (ISO)}</li>
482      * <li>{@code 2012-12-04T12:00 (ISO)}</li>
483      * <li>{@code 2555-12-04T12:00 (ThaiBuddhist)}</li>
484      * <li>{@code 2012-12-05T12:00 (ISO)}</li>
485      * </ol>
486      * Values #2 and #3 represent the same date-time on the time-line.
487      * When two values represent the same date-time, the chronology ID is compared to distinguish them.
488      * This step is needed to make the ordering "consistent with equals".
489      * <p>
490      * If all the date-time objects being compared are in the same chronology, then the
491      * additional chronology stage is not required and only the local date-time is used.
492      * <p>
493      * This default implementation performs the comparison defined above.
494      *
495      * @param other  the other date-time to compare to, not null
496      * @return the comparator value, negative if less, positive if greater
497      */
498     @Override
compareTo(ChronoLocalDateTime<?> other)499     default int compareTo(ChronoLocalDateTime<?> other) {
500         int cmp = toLocalDate().compareTo(other.toLocalDate());
501         if (cmp == 0) {
502             cmp = toLocalTime().compareTo(other.toLocalTime());
503             if (cmp == 0) {
504                 cmp = getChronology().compareTo(other.getChronology());
505             }
506         }
507         return cmp;
508     }
509 
510     /**
511      * Checks if this date-time is after the specified date-time ignoring the chronology.
512      * <p>
513      * This method differs from the comparison in {@link #compareTo} in that it
514      * only compares the underlying date-time and not the chronology.
515      * This allows dates in different calendar systems to be compared based
516      * on the time-line position.
517      * <p>
518      * This default implementation performs the comparison based on the epoch-day
519      * and nano-of-day.
520      *
521      * @param other  the other date-time to compare to, not null
522      * @return true if this is after the specified date-time
523      */
isAfter(ChronoLocalDateTime<?> other)524     default boolean isAfter(ChronoLocalDateTime<?> other) {
525         long thisEpDay = this.toLocalDate().toEpochDay();
526         long otherEpDay = other.toLocalDate().toEpochDay();
527         return thisEpDay > otherEpDay ||
528             (thisEpDay == otherEpDay && this.toLocalTime().toNanoOfDay() > other.toLocalTime().toNanoOfDay());
529     }
530 
531     /**
532      * Checks if this date-time is before the specified date-time ignoring the chronology.
533      * <p>
534      * This method differs from the comparison in {@link #compareTo} in that it
535      * only compares the underlying date-time and not the chronology.
536      * This allows dates in different calendar systems to be compared based
537      * on the time-line position.
538      * <p>
539      * This default implementation performs the comparison based on the epoch-day
540      * and nano-of-day.
541      *
542      * @param other  the other date-time to compare to, not null
543      * @return true if this is before the specified date-time
544      */
isBefore(ChronoLocalDateTime<?> other)545     default boolean isBefore(ChronoLocalDateTime<?> other) {
546         long thisEpDay = this.toLocalDate().toEpochDay();
547         long otherEpDay = other.toLocalDate().toEpochDay();
548         return thisEpDay < otherEpDay ||
549             (thisEpDay == otherEpDay && this.toLocalTime().toNanoOfDay() < other.toLocalTime().toNanoOfDay());
550     }
551 
552     /**
553      * Checks if this date-time is equal to the specified date-time ignoring the chronology.
554      * <p>
555      * This method differs from the comparison in {@link #compareTo} in that it
556      * only compares the underlying date and time and not the chronology.
557      * This allows date-times in different calendar systems to be compared based
558      * on the time-line position.
559      * <p>
560      * This default implementation performs the comparison based on the epoch-day
561      * and nano-of-day.
562      *
563      * @param other  the other date-time to compare to, not null
564      * @return true if the underlying date-time is equal to the specified date-time on the timeline
565      */
isEqual(ChronoLocalDateTime<?> other)566     default boolean isEqual(ChronoLocalDateTime<?> other) {
567         // Do the time check first, it is cheaper than computing EPOCH day.
568         return this.toLocalTime().toNanoOfDay() == other.toLocalTime().toNanoOfDay() &&
569                this.toLocalDate().toEpochDay() == other.toLocalDate().toEpochDay();
570     }
571 
572     /**
573      * Checks if this date-time is equal to another date-time, including the chronology.
574      * <p>
575      * Compares this date-time with another ensuring that the date-time and chronology are the same.
576      *
577      * @param obj  the object to check, null returns false
578      * @return true if this is equal to the other date
579      */
580     @Override
equals(Object obj)581     boolean equals(Object obj);
582 
583     /**
584      * A hash code for this date-time.
585      *
586      * @return a suitable hash code
587      */
588     @Override
hashCode()589     int hashCode();
590 
591     //-----------------------------------------------------------------------
592     /**
593      * Outputs this date-time as a {@code String}.
594      * <p>
595      * The output will include the full local date-time.
596      *
597      * @return a string representation of this date-time, not null
598      */
599     @Override
toString()600     String toString();
601 
602 }
603