Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/make/src/classes/build/tools/tzdb/ChronoField.java
32287 views
/*1* Copyright (c) 2012, 2013, 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* Copyright (c) 2012, Stephen Colebourne & Michael Nascimento Santos27*28* All rights reserved.29*30* Redistribution and use in source and binary forms, with or without31* modification, are permitted provided that the following conditions are met:32*33* * Redistributions of source code must retain the above copyright notice,34* this list of conditions and the following disclaimer.35*36* * Redistributions in binary form must reproduce the above copyright notice,37* this list of conditions and the following disclaimer in the documentation38* and/or other materials provided with the distribution.39*40* * Neither the name of JSR-310 nor the names of its contributors41* may be used to endorse or promote products derived from this software42* without specific prior written permission.43*44* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS45* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT46* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR47* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR48* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,49* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,50* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR51* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF52* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING53* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS54* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.55*/5657package build.tools.tzdb;5859/**60* A standard set of date/time fields.61*62* @since 1.863*/64enum ChronoField {6566/**67* The second-of-minute.68* <p>69* This counts the second within the minute, from 0 to 59.70* This field has the same meaning for all calendar systems.71*/72SECOND_OF_MINUTE("SecondOfMinute", 0, 59),7374/**75* The second-of-day.76* <p>77* This counts the second within the day, from 0 to (24 * 60 * 60) - 1.78* This field has the same meaning for all calendar systems.79*/80SECOND_OF_DAY("SecondOfDay", 0, 86400 - 1),8182/**83* The minute-of-hour.84* <p>85* This counts the minute within the hour, from 0 to 59.86* This field has the same meaning for all calendar systems.87*/88MINUTE_OF_HOUR("MinuteOfHour", 0, 59),8990/**91* The hour-of-day.92* <p>93* This counts the hour within the day, from 0 to 23.94* This is the hour that would be observed on a standard 24-hour digital clock.95* This field has the same meaning for all calendar systems.96*/97HOUR_OF_DAY("HourOfDay", 0, 23),9899100/**101* The day-of-month.102* <p>103* This represents the concept of the day within the month.104* In the default ISO calendar system, this has values from 1 to 31 in most months.105* April, June, September, November have days from 1 to 30, while February has days106* from 1 to 28, or 29 in a leap year.107* <p>108* Non-ISO calendar systems should implement this field using the most recognized109* day-of-month values for users of the calendar system.110* Normally, this is a count of days from 1 to the length of the month.111*/112DAY_OF_MONTH("DayOfMonth", 1, 31),113114/**115* The month-of-year, such as March.116* <p>117* This represents the concept of the month within the year.118* In the default ISO calendar system, this has values from January (1) to December (12).119* <p>120* Non-ISO calendar systems should implement this field using the most recognized121* month-of-year values for users of the calendar system.122* Normally, this is a count of months starting from 1.123*/124MONTH_OF_YEAR("MonthOfYear", 1, 12),125126/**127* The proleptic year, such as 2012.128* <p>129* This represents the concept of the year, counting sequentially and using negative numbers.130* The proleptic year is not interpreted in terms of the era.131* See {@link #YEAR_OF_ERA} for an example showing the mapping from proleptic year to year-of-era.132* <p>133* The standard mental model for a date is based on three concepts - year, month and day.134* These map onto the {@code YEAR}, {@code MONTH_OF_YEAR} and {@code DAY_OF_MONTH} fields.135* Note that there is no reference to eras.136* The full model for a date requires four concepts - era, year, month and day. These map onto137* the {@code ERA}, {@code YEAR_OF_ERA}, {@code MONTH_OF_YEAR} and {@code DAY_OF_MONTH} fields.138* Whether this field or {@code YEAR_OF_ERA} is used depends on which mental model is being used.139* See {@link ChronoLocalDate} for more discussion on this topic.140* <p>141* Non-ISO calendar systems should implement this field as follows.142* If the calendar system has only two eras, before and after a fixed date, then the143* proleptic-year value must be the same as the year-of-era value for the later era,144* and increasingly negative for the earlier era.145* If the calendar system has more than two eras, then the proleptic-year value may be146* defined with any appropriate value, although defining it to be the same as ISO may be147* the best option.148*/149YEAR("Year", -999_999_999, 999_999_999);150151private final String name;152private final int min;153private final int max;154155private ChronoField(String name, int min, int max) {156this.name = name;157this.min= min;158this.max= max;159}160161/**162* Checks that the specified value is valid for this field.163* <p>164*165* @param value the value to check166* @return the value that was passed in167*/168public int checkValidValue(int value) {169if (value >= min && value <= max) {170return value;171}172throw new DateTimeException("Invalid value for " + name + " value: " + value);173}174175public String toString() {176return name;177}178179}180181182