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