1 /* 2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 /* 27 * Copyright (c) 2012, Stephen Colebourne & Michael Nascimento Santos 28 * 29 * All rights reserved. 30 * 31 * Redistribution and use in source and binary forms, with or without 32 * modification, are permitted provided that the following conditions are met: 33 * 34 * * Redistributions of source code must retain the above copyright notice, 35 * this list of conditions and the following disclaimer. 36 * 37 * * Redistributions in binary form must reproduce the above copyright notice, 38 * this list of conditions and the following disclaimer in the documentation 39 * and/or other materials provided with the distribution. 40 * 41 * * Neither the name of JSR-310 nor the names of its contributors 42 * may be used to endorse or promote products derived from this software 43 * without specific prior written permission. 44 * 45 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 46 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 47 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 48 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 49 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 50 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 51 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 52 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 53 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 54 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 55 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 56 */ 57 58 package build.tools.tzdb; 59 60 /** 61 * A standard set of date/time fields. 62 * 63 * @since 1.8 64 */ 65 enum ChronoField { 66 67 /** 68 * The second-of-minute. 69 * <p> 70 * This counts the second within the minute, from 0 to 59. 71 * This field has the same meaning for all calendar systems. 72 */ 73 SECOND_OF_MINUTE("SecondOfMinute", 0, 59), 74 75 /** 76 * The second-of-day. 77 * <p> 78 * This counts the second within the day, from 0 to (24 * 60 * 60) - 1. 79 * This field has the same meaning for all calendar systems. 80 */ 81 SECOND_OF_DAY("SecondOfDay", 0, 86400 - 1), 82 83 /** 84 * The minute-of-hour. 85 * <p> 86 * This counts the minute within the hour, from 0 to 59. 87 * This field has the same meaning for all calendar systems. 88 */ 89 MINUTE_OF_HOUR("MinuteOfHour", 0, 59), 90 91 /** 92 * The hour-of-day. 93 * <p> 94 * This counts the hour within the day, from 0 to 23. 95 * This is the hour that would be observed on a standard 24-hour digital clock. 96 * This field has the same meaning for all calendar systems. 97 */ 98 HOUR_OF_DAY("HourOfDay", 0, 23), 99 100 101 /** 102 * The day-of-month. 103 * <p> 104 * This represents the concept of the day within the month. 105 * In the default ISO calendar system, this has values from 1 to 31 in most months. 106 * April, June, September, November have days from 1 to 30, while February has days 107 * from 1 to 28, or 29 in a leap year. 108 * <p> 109 * Non-ISO calendar systems should implement this field using the most recognized 110 * day-of-month values for users of the calendar system. 111 * Normally, this is a count of days from 1 to the length of the month. 112 */ 113 DAY_OF_MONTH("DayOfMonth", 1, 31), 114 115 /** 116 * The month-of-year, such as March. 117 * <p> 118 * This represents the concept of the month within the year. 119 * In the default ISO calendar system, this has values from January (1) to December (12). 120 * <p> 121 * Non-ISO calendar systems should implement this field using the most recognized 122 * month-of-year values for users of the calendar system. 123 * Normally, this is a count of months starting from 1. 124 */ 125 MONTH_OF_YEAR("MonthOfYear", 1, 12), 126 127 /** 128 * The proleptic year, such as 2012. 129 * <p> 130 * This represents the concept of the year, counting sequentially and using negative numbers. 131 * The proleptic year is not interpreted in terms of the era. 132 * See {@link #YEAR_OF_ERA} for an example showing the mapping from proleptic year to year-of-era. 133 * <p> 134 * The standard mental model for a date is based on three concepts - year, month and day. 135 * These map onto the {@code YEAR}, {@code MONTH_OF_YEAR} and {@code DAY_OF_MONTH} fields. 136 * Note that there is no reference to eras. 137 * The full model for a date requires four concepts - era, year, month and day. These map onto 138 * the {@code ERA}, {@code YEAR_OF_ERA}, {@code MONTH_OF_YEAR} and {@code DAY_OF_MONTH} fields. 139 * Whether this field or {@code YEAR_OF_ERA} is used depends on which mental model is being used. 140 * See {@link ChronoLocalDate} for more discussion on this topic. 141 * <p> 142 * Non-ISO calendar systems should implement this field as follows. 143 * If the calendar system has only two eras, before and after a fixed date, then the 144 * proleptic-year value must be the same as the year-of-era value for the later era, 145 * and increasingly negative for the earlier era. 146 * If the calendar system has more than two eras, then the proleptic-year value may be 147 * defined with any appropriate value, although defining it to be the same as ISO may be 148 * the best option. 149 */ 150 YEAR("Year", -999_999_999, 999_999_999); 151 152 private final String name; 153 private final int min; 154 private final int max; 155 156 private ChronoField(String name, int min, int max) { 157 this.name = name; 158 this.min= min; 159 this.max= max; 160 } 161 162 /** 163 * Checks that the specified value is valid for this field. 164 * <p> 165 * 166 * @param value the value to check 167 * @return the value that was passed in 168 */ 169 public int checkValidValue(int value) { 170 if (value >= min && value <= max) { 171 return value; 172 } 173 throw new DateTimeException("Invalid value for " + name + " value: " + value); 174 } 175 176 public String toString() { 177 return name; 178 } 179 180 }