jdk/src/share/classes/java/time/temporal/ISOChrono.java
author sherman
Tue, 22 Jan 2013 20:59:21 -0800
changeset 15289 3ac550392e43
permissions -rw-r--r--
8003680: JSR 310 Date/Time API Summary: Integration of JSR310 Date/Time API for M6 Reviewed-by: alanb, naoto, dholmes Contributed-by: scolebourne@joda.org, roger.riggs@oracle.com, richard.warburton@gmail.com, misterm@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     1
/*
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     2
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     4
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    10
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    15
 * accompanied this code).
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    16
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    20
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    23
 * questions.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    24
 */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    25
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    26
/*
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    27
 * This file is available under and governed by the GNU General Public
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    28
 * License version 2 only, as published by the Free Software Foundation.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    29
 * However, the following notice accompanied the original version of this
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    30
 * file:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    31
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    32
 * Copyright (c) 2012, Stephen Colebourne & Michael Nascimento Santos
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    33
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    34
 * All rights reserved.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    35
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    36
 * Redistribution and use in source and binary forms, with or without
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    37
 * modification, are permitted provided that the following conditions are met:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    38
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    39
 *  * Redistributions of source code must retain the above copyright notice,
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    40
 *    this list of conditions and the following disclaimer.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    41
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    42
 *  * Redistributions in binary form must reproduce the above copyright notice,
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    43
 *    this list of conditions and the following disclaimer in the documentation
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    44
 *    and/or other materials provided with the distribution.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    45
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    46
 *  * Neither the name of JSR-310 nor the names of its contributors
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    47
 *    may be used to endorse or promote products derived from this software
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    48
 *    without specific prior written permission.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    49
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    50
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    51
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    52
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    53
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    54
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    55
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    56
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    57
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    58
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    59
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    60
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    61
 */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    62
package java.time.temporal;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    63
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    64
import java.io.Serializable;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    65
import java.time.Clock;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    66
import java.time.DateTimeException;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    67
import java.time.Instant;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    68
import java.time.LocalDate;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    69
import java.time.LocalDateTime;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    70
import java.time.ZoneId;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    71
import java.time.ZonedDateTime;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    72
import java.util.Arrays;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    73
import java.util.List;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    74
import java.util.Locale;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    75
import java.util.Objects;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    76
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    77
/**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    78
 * The ISO calendar system.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    79
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    80
 * This chronology defines the rules of the ISO calendar system.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    81
 * This calendar system is based on the ISO-8601 standard, which is the
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    82
 * <i>de facto</i> world calendar.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    83
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    84
 * The fields are defined as follows:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    85
 * <p><ul>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    86
 * <li>era - There are two eras, 'Current Era' (CE) and 'Before Current Era' (BCE).
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    87
 * <li>year-of-era - The year-of-era is the same as the proleptic-year for the current CE era.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    88
 *  For the BCE era before the ISO epoch the year increases from 1 upwards as time goes backwards.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    89
 * <li>proleptic-year - The proleptic year is the same as the year-of-era for the
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    90
 *  current era. For the previous era, years have zero, then negative values.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    91
 * <li>month-of-year - There are 12 months in an ISO year, numbered from 1 to 12.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    92
 * <li>day-of-month - There are between 28 and 31 days in each of the ISO month, numbered from 1 to 31.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    93
 *  Months 4, 6, 9 and 11 have 30 days, Months 1, 3, 5, 7, 8, 10 and 12 have 31 days.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    94
 *  Month 2 has 28 days, or 29 in a leap year.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    95
 * <li>day-of-year - There are 365 days in a standard ISO year and 366 in a leap year.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    96
 *  The days are numbered from 1 to 365 or 1 to 366.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    97
 * <li>leap-year - Leap years occur every 4 years, except where the year is divisble by 100 and not divisble by 400.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    98
 * </ul><p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    99
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   100
 * <h3>Specification for implementors</h3>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   101
 * This class is immutable and thread-safe.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   102
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   103
 * @since 1.8
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   104
 */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   105
public final class ISOChrono extends Chrono<ISOChrono> implements Serializable {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   106
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   107
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   108
     * Singleton instance of the ISO chronology.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   109
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   110
    public static final ISOChrono INSTANCE = new ISOChrono();
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   111
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   112
     * The singleton instance for the era BCE - 'Before Current Era'.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   113
     * The 'ISO' part of the name emphasizes that this differs from the BCE
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   114
     * era in the Gregorian calendar system.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   115
     * This has the numeric value of {@code 0}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   116
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   117
    public static final Era<ISOChrono> ERA_BCE = ISOEra.BCE;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   118
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   119
     * The singleton instance for the era CE - 'Current Era'.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   120
     * The 'ISO' part of the name emphasizes that this differs from the CE
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   121
     * era in the Gregorian calendar system.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   122
     * This has the numeric value of {@code 1}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   123
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   124
    public static final Era<ISOChrono> ERA_CE = ISOEra.CE;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   125
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   126
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   127
     * Serialization version.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   128
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   129
    private static final long serialVersionUID = -1440403870442975015L;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   130
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   131
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   132
     * Restricted constructor.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   133
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   134
    private ISOChrono() {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   135
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   136
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   137
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   138
     * Resolve singleton.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   139
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   140
     * @return the singleton instance, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   141
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   142
    private Object readResolve() {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   143
        return INSTANCE;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   144
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   145
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   146
    //-----------------------------------------------------------------------
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   147
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   148
     * Gets the ID of the chronology - 'ISO'.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   149
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   150
     * The ID uniquely identifies the {@code Chrono}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   151
     * It can be used to lookup the {@code Chrono} using {@link #of(String)}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   152
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   153
     * @return the chronology ID - 'ISO'
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   154
     * @see #getCalendarType()
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   155
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   156
    @Override
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   157
    public String getId() {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   158
        return "ISO";
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   159
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   160
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   161
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   162
     * Gets the calendar type of the underlying calendar system - 'iso8601'.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   163
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   164
     * The calendar type is an identifier defined by the
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   165
     * <em>Unicode Locale Data Markup Language (LDML)</em> specification.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   166
     * It can be used to lookup the {@code Chrono} using {@link #of(String)}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   167
     * It can also be used as part of a locale, accessible via
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   168
     * {@link Locale#getUnicodeLocaleType(String)} with the key 'ca'.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   169
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   170
     * @return the calendar system type - 'iso8601'
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   171
     * @see #getId()
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   172
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   173
    @Override
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   174
    public String getCalendarType() {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   175
        return "iso8601";
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   176
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   177
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   178
    //-----------------------------------------------------------------------
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   179
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   180
     * Obtains an ISO local date from the era, year-of-era, month-of-year
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   181
     * and day-of-month fields.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   182
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   183
     * @param era  the ISO era, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   184
     * @param yearOfEra  the ISO year-of-era
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   185
     * @param month  the ISO month-of-year
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   186
     * @param dayOfMonth  the ISO day-of-month
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   187
     * @return the ISO local date, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   188
     * @throws DateTimeException if unable to create the date
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   189
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   190
    @Override  // override with covariant return type
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   191
    public LocalDate date(Era<ISOChrono> era, int yearOfEra, int month, int dayOfMonth) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   192
        return date(prolepticYear(era, yearOfEra), month, dayOfMonth);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   193
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   194
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   195
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   196
     * Obtains an ISO local date from the proleptic-year, month-of-year
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   197
     * and day-of-month fields.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   198
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   199
     * This is equivalent to {@link LocalDate#of(int, int, int)}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   200
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   201
     * @param prolepticYear  the ISO proleptic-year
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   202
     * @param month  the ISO month-of-year
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   203
     * @param dayOfMonth  the ISO day-of-month
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   204
     * @return the ISO local date, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   205
     * @throws DateTimeException if unable to create the date
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   206
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   207
    @Override  // override with covariant return type
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   208
    public LocalDate date(int prolepticYear, int month, int dayOfMonth) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   209
        return LocalDate.of(prolepticYear, month, dayOfMonth);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   210
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   211
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   212
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   213
     * Obtains an ISO local date from the era, year-of-era and day-of-year fields.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   214
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   215
     * @param era  the ISO era, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   216
     * @param yearOfEra  the ISO year-of-era
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   217
     * @param dayOfYear  the ISO day-of-year
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   218
     * @return the ISO local date, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   219
     * @throws DateTimeException if unable to create the date
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   220
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   221
    @Override  // override with covariant return type
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   222
    public LocalDate dateYearDay(Era<ISOChrono> era, int yearOfEra, int dayOfYear) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   223
        return dateYearDay(prolepticYear(era, yearOfEra), dayOfYear);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   224
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   225
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   226
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   227
     * Obtains an ISO local date from the proleptic-year and day-of-year fields.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   228
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   229
     * This is equivalent to {@link LocalDate#ofYearDay(int, int)}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   230
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   231
     * @param prolepticYear  the ISO proleptic-year
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   232
     * @param dayOfYear  the ISO day-of-year
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   233
     * @return the ISO local date, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   234
     * @throws DateTimeException if unable to create the date
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   235
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   236
    @Override  // override with covariant return type
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   237
    public LocalDate dateYearDay(int prolepticYear, int dayOfYear) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   238
        return LocalDate.ofYearDay(prolepticYear, dayOfYear);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   239
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   240
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   241
    //-----------------------------------------------------------------------
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   242
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   243
     * Obtains an ISO local date from another date-time object.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   244
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   245
     * This is equivalent to {@link LocalDate#from(TemporalAccessor)}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   246
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   247
     * @param temporal  the date-time object to convert, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   248
     * @return the ISO local date, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   249
     * @throws DateTimeException if unable to create the date
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   250
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   251
    @Override  // override with covariant return type
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   252
    public LocalDate date(TemporalAccessor temporal) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   253
        return LocalDate.from(temporal);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   254
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   255
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   256
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   257
     * Obtains an ISO local date-time from another date-time object.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   258
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   259
     * This is equivalent to {@link LocalDateTime#from(TemporalAccessor)}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   260
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   261
     * @param temporal  the date-time object to convert, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   262
     * @return the ISO local date-time, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   263
     * @throws DateTimeException if unable to create the date-time
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   264
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   265
    @Override  // override with covariant return type
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   266
    public LocalDateTime localDateTime(TemporalAccessor temporal) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   267
        return LocalDateTime.from(temporal);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   268
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   269
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   270
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   271
     * Obtains an ISO zoned date-time from another date-time object.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   272
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   273
     * This is equivalent to {@link ZonedDateTime#from(TemporalAccessor)}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   274
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   275
     * @param temporal  the date-time object to convert, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   276
     * @return the ISO zoned date-time, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   277
     * @throws DateTimeException if unable to create the date-time
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   278
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   279
    @Override  // override with covariant return type
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   280
    public ZonedDateTime zonedDateTime(TemporalAccessor temporal) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   281
        return ZonedDateTime.from(temporal);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   282
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   283
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   284
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   285
     * Obtains an ISO zoned date-time in this chronology from an {@code Instant}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   286
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   287
     * This is equivalent to {@link ZonedDateTime#ofInstant(Instant, ZoneId)}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   288
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   289
     * @param instant  the instant to create the date-time from, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   290
     * @param zone  the time-zone, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   291
     * @return the zoned date-time, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   292
     * @throws DateTimeException if the result exceeds the supported range
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   293
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   294
    public ZonedDateTime zonedDateTime(Instant instant, ZoneId zone) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   295
        return ZonedDateTime.ofInstant(instant, zone);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   296
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   297
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   298
    //-----------------------------------------------------------------------
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   299
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   300
     * Obtains the current ISO local date from the system clock in the default time-zone.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   301
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   302
     * This will query the {@link Clock#systemDefaultZone() system clock} in the default
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   303
     * time-zone to obtain the current date.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   304
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   305
     * Using this method will prevent the ability to use an alternate clock for testing
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   306
     * because the clock is hard-coded.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   307
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   308
     * @return the current ISO local date using the system clock and default time-zone, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   309
     * @throws DateTimeException if unable to create the date
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   310
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   311
    @Override  // override with covariant return type
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   312
    public LocalDate dateNow() {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   313
        return dateNow(Clock.systemDefaultZone());
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   314
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   315
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   316
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   317
     * Obtains the current ISO local date from the system clock in the specified time-zone.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   318
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   319
     * This will query the {@link Clock#system(ZoneId) system clock} to obtain the current date.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   320
     * Specifying the time-zone avoids dependence on the default time-zone.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   321
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   322
     * Using this method will prevent the ability to use an alternate clock for testing
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   323
     * because the clock is hard-coded.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   324
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   325
     * @return the current ISO local date using the system clock, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   326
     * @throws DateTimeException if unable to create the date
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   327
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   328
    @Override  // override with covariant return type
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   329
    public LocalDate dateNow(ZoneId zone) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   330
        return dateNow(Clock.system(zone));
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   331
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   332
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   333
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   334
     * Obtains the current ISO local date from the specified clock.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   335
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   336
     * This will query the specified clock to obtain the current date - today.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   337
     * Using this method allows the use of an alternate clock for testing.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   338
     * The alternate clock may be introduced using {@link Clock dependency injection}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   339
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   340
     * @param clock  the clock to use, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   341
     * @return the current ISO local date, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   342
     * @throws DateTimeException if unable to create the date
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   343
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   344
    @Override  // override with covariant return type
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   345
    public LocalDate dateNow(Clock clock) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   346
        Objects.requireNonNull(clock, "clock");
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   347
        return date(LocalDate.now(clock));
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   348
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   349
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   350
    //-----------------------------------------------------------------------
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   351
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   352
     * Checks if the year is a leap year, according to the ISO proleptic
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   353
     * calendar system rules.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   354
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   355
     * This method applies the current rules for leap years across the whole time-line.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   356
     * In general, a year is a leap year if it is divisible by four without
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   357
     * remainder. However, years divisible by 100, are not leap years, with
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   358
     * the exception of years divisible by 400 which are.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   359
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   360
     * For example, 1904 is a leap year it is divisible by 4.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   361
     * 1900 was not a leap year as it is divisible by 100, however 2000 was a
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   362
     * leap year as it is divisible by 400.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   363
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   364
     * The calculation is proleptic - applying the same rules into the far future and far past.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   365
     * This is historically inaccurate, but is correct for the ISO-8601 standard.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   366
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   367
     * @param prolepticYear  the ISO proleptic year to check
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   368
     * @return true if the year is leap, false otherwise
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   369
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   370
    @Override
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   371
    public boolean isLeapYear(long prolepticYear) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   372
        return ((prolepticYear & 3) == 0) && ((prolepticYear % 100) != 0 || (prolepticYear % 400) == 0);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   373
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   374
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   375
    @Override
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   376
    public int prolepticYear(Era<ISOChrono> era, int yearOfEra) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   377
        if (era instanceof ISOEra == false) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   378
            throw new DateTimeException("Era must be ISOEra");
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   379
        }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   380
        return (era == ISOEra.CE ? yearOfEra : 1 - yearOfEra);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   381
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   382
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   383
    @Override
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   384
    public Era<ISOChrono> eraOf(int eraValue) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   385
        return ISOEra.of(eraValue);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   386
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   387
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   388
    @Override
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   389
    public List<Era<ISOChrono>> eras() {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   390
        return Arrays.<Era<ISOChrono>>asList(ISOEra.values());
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   391
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   392
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   393
    //-----------------------------------------------------------------------
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   394
    @Override
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   395
    public ValueRange range(ChronoField field) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   396
        return field.range();
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   397
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   398
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   399
}