src/java.base/share/classes/java/time/package-info.java
author vromero
Thu, 11 Apr 2019 22:56:11 -0400
changeset 54520 f48312257bc6
parent 49508 8f041818aca9
permissions -rw-r--r--
8222151: refactoring: enhancements to java.lang.Class::methodToString and java.lang.Class::getTypeName Reviewed-by: darcy Contributed-by: sergei.tsypanov@yandex.ru
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     1
/*
49508
8f041818aca9 8199176: Accessibility issues in java.base docs
joehw
parents: 47216
diff changeset
     2
 * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
15289
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
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    63
/**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    64
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    65
 * The main API for dates, times, instants, and durations.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    66
 * </p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    67
 * <p>
28751
47403deaec44 8068284: Missing @throws in DateTimeFormatterBuilder.appendOffset
rriggs
parents: 25859
diff changeset
    68
 * The classes defined here represent the principle date-time concepts,
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    69
 * including instants, durations, dates, times, time-zones and periods.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    70
 * They are based on the ISO calendar system, which is the <i>de facto</i> world
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    71
 * calendar following the proleptic Gregorian rules.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    72
 * All the classes are immutable and thread-safe.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    73
 * </p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    74
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    75
 * Each date time instance is composed of fields that are conveniently
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    76
 * made available by the APIs.  For lower level access to the fields refer
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    77
 * to the {@code java.time.temporal} package.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    78
 * Each class includes support for printing and parsing all manner of dates and times.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    79
 * Refer to the {@code java.time.format} package for customization options.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    80
 * </p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    81
 * <p>
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
    82
 * The {@code java.time.chrono} package contains the calendar neutral API
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
    83
 * {@link java.time.chrono.ChronoLocalDate ChronoLocalDate},
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
    84
 * {@link java.time.chrono.ChronoLocalDateTime ChronoLocalDateTime},
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
    85
 * {@link java.time.chrono.ChronoZonedDateTime ChronoZonedDateTime} and
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
    86
 * {@link java.time.chrono.Era Era}.
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    87
 * This is intended for use by applications that need to use localized calendars.
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
    88
 * It is recommended that applications use the ISO-8601 date and time classes from
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    89
 * this package across system boundaries, such as to the database or across the network.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    90
 * The calendar neutral API should be reserved for interactions with users.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    91
 * </p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    92
 *
49508
8f041818aca9 8199176: Accessibility issues in java.base docs
joehw
parents: 47216
diff changeset
    93
 * <h2>Dates and Times</h2>
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    94
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    95
 * {@link java.time.Instant} is essentially a numeric timestamp.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    96
 * The current Instant can be retrieved from a {@link java.time.Clock}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    97
 * This is useful for logging and persistence of a point in time
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    98
 * and has in the past been associated with storing the result
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    99
 * from {@link java.lang.System#currentTimeMillis()}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   100
 * </p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   101
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   102
 * {@link java.time.LocalDate} stores a date without a time.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   103
 * This stores a date like '2010-12-03' and could be used to store a birthday.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   104
 * </p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   105
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   106
 * {@link java.time.LocalTime} stores a time without a date.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   107
 * This stores a time like '11:30' and could be used to store an opening or closing time.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   108
 * </p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   109
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   110
 * {@link java.time.LocalDateTime} stores a date and time.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   111
 * This stores a date-time like '2010-12-03T11:30'.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   112
 * </p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   113
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   114
 * {@link java.time.ZonedDateTime} stores a date and time with a time-zone.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   115
 * This is useful if you want to perform accurate calculations of
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   116
 * dates and times taking into account the {@link java.time.ZoneId}, such as 'Europe/Paris'.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   117
 * Where possible, it is recommended to use a simpler class without a time-zone.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   118
 * The widespread use of time-zones tends to add considerable complexity to an application.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   119
 * </p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   120
 *
49508
8f041818aca9 8199176: Accessibility issues in java.base docs
joehw
parents: 47216
diff changeset
   121
 * <h2>Duration and Period</h2>
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   122
 * <p>
30821
9bc6f2e9966b 8075678: java.time javadoc error in DateTimeFormatter::parsedLeapSecond
rriggs
parents: 28751
diff changeset
   123
 * Beyond dates and times, the API also allows the storage of periods and durations of time.
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   124
 * A {@link java.time.Duration} is a simple measure of time along the time-line in nanoseconds.
30821
9bc6f2e9966b 8075678: java.time javadoc error in DateTimeFormatter::parsedLeapSecond
rriggs
parents: 28751
diff changeset
   125
 * A {@link java.time.Period} expresses an amount of time in units meaningful
9bc6f2e9966b 8075678: java.time javadoc error in DateTimeFormatter::parsedLeapSecond
rriggs
parents: 28751
diff changeset
   126
 * to humans, such as years or days.
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   127
 * </p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   128
 *
49508
8f041818aca9 8199176: Accessibility issues in java.base docs
joehw
parents: 47216
diff changeset
   129
 * <h2>Additional value types</h2>
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   130
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   131
 * {@link java.time.Month} stores a month on its own.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   132
 * This stores a single month-of-year in isolation, such as 'DECEMBER'.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   133
 * </p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   134
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   135
 * {@link java.time.DayOfWeek} stores a day-of-week on its own.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   136
 * This stores a single day-of-week in isolation, such as 'TUESDAY'.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   137
 * </p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   138
 * <p>
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   139
 * {@link java.time.Year} stores a year on its own.
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   140
 * This stores a single year in isolation, such as '2010'.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   141
 * </p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   142
 * <p>
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   143
 * {@link java.time.YearMonth} stores a year and month without a day or time.
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   144
 * This stores a year and month, such as '2010-12' and could be used for a credit card expiry.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   145
 * </p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   146
 * <p>
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   147
 * {@link java.time.MonthDay} stores a month and day without a year or time.
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   148
 * This stores a month and day-of-month, such as '--12-03' and
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   149
 * could be used to store an annual event like a birthday without storing the year.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   150
 * </p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   151
 * <p>
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   152
 * {@link java.time.OffsetTime} stores a time and offset from UTC without a date.
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   153
 * This stores a date like '11:30+01:00'.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   154
 * The {@link java.time.ZoneOffset ZoneOffset} is of the form '+01:00'.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   155
 * </p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   156
 * <p>
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   157
 * {@link java.time.OffsetDateTime} stores a date and time and offset from UTC.
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   158
 * This stores a date-time like '2010-12-03T11:30+01:00'.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   159
 * This is sometimes found in XML messages and other forms of persistence,
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   160
 * but contains less information than a full time-zone.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   161
 * </p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   162
 *
49508
8f041818aca9 8199176: Accessibility issues in java.base docs
joehw
parents: 47216
diff changeset
   163
 * <h2>Package specification</h2>
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   164
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   165
 * Unless otherwise noted, passing a null argument to a constructor or method in any class or interface
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   166
 * in this package will cause a {@link java.lang.NullPointerException NullPointerException} to be thrown.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   167
 * The Javadoc "@param" definition is used to summarise the null-behavior.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   168
 * The "@throws {@link java.lang.NullPointerException}" is not explicitly documented in each method.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   169
 * </p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   170
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   171
 * All calculations should check for numeric overflow and throw either an {@link java.lang.ArithmeticException}
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   172
 * or a {@link java.time.DateTimeException}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   173
 * </p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   174
 *
49508
8f041818aca9 8199176: Accessibility issues in java.base docs
joehw
parents: 47216
diff changeset
   175
 * <h2>Design notes (non normative)</h2>
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   176
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   177
 * The API has been designed to reject null early and to be clear about this behavior.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   178
 * A key exception is any method that takes an object and returns a boolean, for the purpose
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   179
 * of checking or validating, will generally return false for null.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   180
 * </p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   181
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   182
 * The API is designed to be type-safe where reasonable in the main high-level API.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   183
 * Thus, there are separate classes for the distinct concepts of date, time and date-time,
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   184
 * plus variants for offset and time-zone.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   185
 * This can seem like a lot of classes, but most applications can begin with just five date/time types.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   186
 * <ul>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   187
 * <li>{@link java.time.Instant} - a timestamp</li>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   188
 * <li>{@link java.time.LocalDate} - a date without a time, or any reference to an offset or time-zone</li>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   189
 * <li>{@link java.time.LocalTime} - a time without a date, or any reference to an offset or time-zone</li>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   190
 * <li>{@link java.time.LocalDateTime} - combines date and time, but still without any offset or time-zone</li>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   191
 * <li>{@link java.time.ZonedDateTime} - a "full" date-time with time-zone and resolved offset from UTC/Greenwich</li>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   192
 * </ul>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   193
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   194
 * {@code Instant} is the closest equivalent class to {@code java.util.Date}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   195
 * {@code ZonedDateTime} is the closest equivalent class to {@code java.util.GregorianCalendar}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   196
 * </p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   197
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   198
 * Where possible, applications should use {@code LocalDate}, {@code LocalTime} and {@code LocalDateTime}
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   199
 * to better model the domain. For example, a birthday should be stored in a code {@code LocalDate}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   200
 * Bear in mind that any use of a {@linkplain java.time.ZoneId time-zone}, such as 'Europe/Paris', adds
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   201
 * considerable complexity to a calculation.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   202
 * Many applications can be written only using {@code LocalDate}, {@code LocalTime} and {@code Instant},
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   203
 * with the time-zone added at the user interface (UI) layer.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   204
 * </p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   205
 * <p>
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   206
 * The offset-based date-time types {@code OffsetTime} and {@code OffsetDateTime},
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   207
 * are intended primarily for use with network protocols and database access.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   208
 * For example, most databases cannot automatically store a time-zone like 'Europe/Paris', but
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   209
 * they can store an offset like '+02:00'.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   210
 * </p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   211
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   212
 * Classes are also provided for the most important sub-parts of a date, including {@code Month},
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   213
 * {@code DayOfWeek}, {@code Year}, {@code YearMonth} and {@code MonthDay}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   214
 * These can be used to model more complex date-time concepts.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   215
 * For example, {@code YearMonth} is useful for representing a credit card expiry.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   216
 * </p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   217
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   218
 * Note that while there are a large number of classes representing different aspects of dates,
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   219
 * there are relatively few dealing with different aspects of time.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   220
 * Following type-safety to its logical conclusion would have resulted in classes for
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   221
 * hour-minute, hour-minute-second and hour-minute-second-nanosecond.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   222
 * While logically pure, this was not a practical option as it would have almost tripled the
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   223
 * number of classes due to the combinations of date and time.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   224
 * Thus, {@code LocalTime} is used for all precisions of time, with zeroes used to imply lower precision.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   225
 * </p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   226
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   227
 * Following full type-safety to its ultimate conclusion might also argue for a separate class
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   228
 * for each field in date-time, such as a class for HourOfDay and another for DayOfMonth.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   229
 * This approach was tried, but was excessively complicated in the Java language, lacking usability.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   230
 * A similar problem occurs with periods.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   231
 * There is a case for a separate class for each period unit, such as a type for Years and a type for Minutes.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   232
 * However, this yields a lot of classes and a problem of type conversion.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   233
 * Thus, the set of date-time types provided is a compromise between purity and practicality.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   234
 * </p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   235
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   236
 * The API has a relatively large surface area in terms of number of methods.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   237
 * This is made manageable through the use of consistent method prefixes.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   238
 * <ul>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   239
 * <li>{@code of} - static factory method</li>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   240
 * <li>{@code parse} - static factory method focussed on parsing</li>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   241
 * <li>{@code get} - gets the value of something</li>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   242
 * <li>{@code is} - checks if something is true</li>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   243
 * <li>{@code with} - the immutable equivalent of a setter</li>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   244
 * <li>{@code plus} - adds an amount to an object</li>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   245
 * <li>{@code minus} - subtracts an amount from an object</li>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   246
 * <li>{@code to} - converts this object to another type</li>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   247
 * <li>{@code at} - combines this object with another, such as {@code date.atTime(time)}</li>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   248
 * </ul>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   249
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   250
 * Multiple calendar systems is an awkward addition to the design challenges.
28751
47403deaec44 8068284: Missing @throws in DateTimeFormatterBuilder.appendOffset
rriggs
parents: 25859
diff changeset
   251
 * The first principle is that most users want the standard ISO calendar system.
47403deaec44 8068284: Missing @throws in DateTimeFormatterBuilder.appendOffset
rriggs
parents: 25859
diff changeset
   252
 * As such, the main classes are ISO-only. The second principle is that most of those that want a
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   253
 * non-ISO calendar system want it for user interaction, thus it is a UI localization issue.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   254
 * As such, date and time objects should be held as ISO objects in the data model and persistent
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   255
 * storage, only being converted to and from a local calendar for display.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   256
 * The calendar system would be stored separately in the user preferences.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   257
 * </p>
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
 * There are, however, some limited use cases where users believe they need to store and use
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   260
 * dates in arbitrary calendar systems throughout the application.
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   261
 * This is supported by {@link java.time.chrono.ChronoLocalDate}, however it is vital to read
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   262
 * all the associated warnings in the Javadoc of that interface before using it.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   263
 * In summary, applications that require general interoperation between multiple calendar systems
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   264
 * typically need to be written in a very different way to those only using the ISO calendar,
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   265
 * thus most applications should just use ISO and avoid {@code ChronoLocalDate}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   266
 * </p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   267
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   268
 * The API is also designed for user extensibility, as there are many ways of calculating time.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   269
 * The {@linkplain java.time.temporal.TemporalField field} and {@linkplain java.time.temporal.TemporalUnit unit}
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   270
 * API, accessed via {@link java.time.temporal.TemporalAccessor TemporalAccessor} and
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   271
 * {@link java.time.temporal.Temporal Temporal} provide considerable flexibility to applications.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   272
 * In addition, the {@link java.time.temporal.TemporalQuery TemporalQuery} and
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   273
 * {@link java.time.temporal.TemporalAdjuster TemporalAdjuster} interfaces provide day-to-day
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   274
 * power, allowing code to read close to business requirements:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   275
 * </p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   276
 * <pre>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   277
 *   LocalDate customerBirthday = customer.loadBirthdayFromDatabase();
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   278
 *   LocalDate today = LocalDate.now();
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   279
 *   if (customerBirthday.equals(today)) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   280
 *     LocalDate specialOfferExpiryDate = today.plusWeeks(2).with(next(FRIDAY));
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   281
 *     customer.sendBirthdaySpecialOffer(specialOfferExpiryDate);
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
 * </pre>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   285
 *
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 15658
diff changeset
   286
 * @since 1.8
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   287
 */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   288
package java.time;