Path: blob/master/src/java.base/share/classes/java/time/temporal/package-info.java
41159 views
/*1* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26* This file is available under and governed by the GNU General Public27* License version 2 only, as published by the Free Software Foundation.28* However, the following notice accompanied the original version of this29* file:30*31* Copyright (c) 2012, Stephen Colebourne & Michael Nascimento Santos32*33* All rights reserved.34*35* Redistribution and use in source and binary forms, with or without36* modification, are permitted provided that the following conditions are met:37*38* * Redistributions of source code must retain the above copyright notice,39* this list of conditions and the following disclaimer.40*41* * Redistributions in binary form must reproduce the above copyright notice,42* this list of conditions and the following disclaimer in the documentation43* and/or other materials provided with the distribution.44*45* * Neither the name of JSR-310 nor the names of its contributors46* may be used to endorse or promote products derived from this software47* without specific prior written permission.48*49* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS50* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT51* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR52* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR53* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,54* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,55* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR56* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF57* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING58* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS59* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.60*/6162/**63* <p>64* Access to date and time using fields and units, and date time adjusters.65* </p>66* <p>67* This package expands on the base package to provide additional functionality for68* more powerful use cases. Support is included for:69* </p>70* <ul>71* <li>Units of date-time, such as years, months, days and hours</li>72* <li>Fields of date-time, such as month-of-year, day-of-week or hour-of-day</li>73* <li>Date-time adjustment functions</li>74* <li>Different definitions of weeks</li>75* </ul>76*77* <h2>Fields and Units</h2>78* <p>79* Dates and times are expressed in terms of fields and units.80* A unit is used to measure an amount of time, such as years, days or minutes.81* All units implement {@link java.time.temporal.TemporalUnit}.82* The set of well known units is defined in {@link java.time.temporal.ChronoUnit}, such as {@code DAYS}.83* The unit interface is designed to allow application defined units.84* </p>85* <p>86* A field is used to express part of a larger date-time, such as year, month-of-year or second-of-minute.87* All fields implement {@link java.time.temporal.TemporalField}.88* The set of well known fields are defined in {@link java.time.temporal.ChronoField}, such as {@code HOUR_OF_DAY}.89* Additional fields are defined by {@link java.time.temporal.JulianFields}, {@link java.time.temporal.WeekFields}90* and {@link java.time.temporal.IsoFields}.91* The field interface is designed to allow application defined fields.92* </p>93* <p>94* This package provides tools that allow the units and fields of date and time to be accessed95* in a general way most suited for frameworks.96* {@link java.time.temporal.Temporal} provides the abstraction for date time types that support fields.97* Its methods support getting the value of a field, creating a new date time with the value of98* a field modified, and querying for additional information, typically used to extract the offset or time-zone.99* </p>100* <p>101* One use of fields in application code is to retrieve fields for which there is no convenience method.102* For example, getting the day-of-month is common enough that there is a method on {@code LocalDate}103* called {@code getDayOfMonth()}. However for more unusual fields it is necessary to use the field.104* For example, {@code date.get(ChronoField.ALIGNED_WEEK_OF_MONTH)}.105* The fields also provide access to the range of valid values.106* </p>107*108* <h2>Adjustment and Query</h2>109* <p>110* A key part of the date-time problem space is adjusting a date to a new, related value,111* such as the "last day of the month", or "next Wednesday".112* These are modeled as functions that adjust a base date-time.113* The functions implement {@link java.time.temporal.TemporalAdjuster} and operate on {@code Temporal}.114* A set of common functions are provided in {@link java.time.temporal.TemporalAdjusters}.115* For example, to find the first occurrence of a day-of-week after a given date, use116* {@link java.time.temporal.TemporalAdjusters#next(DayOfWeek)}, such as117* {@code date.with(next(MONDAY))}.118* Applications can also define adjusters by implementing {@link java.time.temporal.TemporalAdjuster}.119* </p>120* <p>121* The {@link java.time.temporal.TemporalAmount} interface models amounts of relative time.122* </p>123* <p>124* In addition to adjusting a date-time, an interface is provided to enable querying via125* {@link java.time.temporal.TemporalQuery}.126* The most common implementations of the query interface are method references.127* The {@code from(TemporalAccessor)} methods on major classes can all be used, such as128* {@code LocalDate::from} or {@code Month::from}.129* Further implementations are provided in {@link java.time.temporal.TemporalQueries} as static methods.130* Applications can also define queries by implementing {@link java.time.temporal.TemporalQuery}.131* </p>132*133* <h2>Weeks</h2>134* <p>135* Different locales have different definitions of the week.136* For example, in Europe the week typically starts on a Monday, while in the US it starts on a Sunday.137* The {@link java.time.temporal.WeekFields} class models this distinction.138* </p>139* <p>140* The ISO calendar system defines an additional week-based division of years.141* This defines a year based on whole Monday to Monday weeks.142* This is modeled in {@link java.time.temporal.IsoFields}.143* </p>144*145* <h2>Package specification</h2>146* <p>147* Unless otherwise noted, passing a null argument to a constructor or method in any class or interface148* in this package will cause a {@link java.lang.NullPointerException NullPointerException} to be thrown.149* The Javadoc "@param" definition is used to summarise the null-behavior.150* The "@throws {@link java.lang.NullPointerException}" is not explicitly documented in each method.151* </p>152* <p>153* All calculations should check for numeric overflow and throw either an {@link java.lang.ArithmeticException}154* or a {@link java.time.DateTimeException}.155* </p>156* @since 1.8157*/158package java.time.temporal;159160161