001/*
002 * Copyright (c) 2007-2013, Stephen Colebourne & Michael Nascimento Santos
003 *
004 * All rights reserved.
005 *
006 * Redistribution and use in source and binary forms, with or without
007 * modification, are permitted provided that the following conditions are met:
008 *
009 *  * Redistributions of source code must retain the above copyright notice,
010 *    this list of conditions and the following disclaimer.
011 *
012 *  * Redistributions in binary form must reproduce the above copyright notice,
013 *    this list of conditions and the following disclaimer in the documentation
014 *    and/or other materials provided with the distribution.
015 *
016 *  * Neither the name of JSR-310 nor the names of its contributors
017 *    may be used to endorse or promote products derived from this software
018 *    without specific prior written permission.
019 *
020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
024 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031 */
032package org.threeten.bp.temporal;
033
034import static org.threeten.bp.temporal.ChronoUnit.DAYS;
035import static org.threeten.bp.temporal.ChronoUnit.ERAS;
036import static org.threeten.bp.temporal.ChronoUnit.FOREVER;
037import static org.threeten.bp.temporal.ChronoUnit.HALF_DAYS;
038import static org.threeten.bp.temporal.ChronoUnit.HOURS;
039import static org.threeten.bp.temporal.ChronoUnit.MICROS;
040import static org.threeten.bp.temporal.ChronoUnit.MILLIS;
041import static org.threeten.bp.temporal.ChronoUnit.MINUTES;
042import static org.threeten.bp.temporal.ChronoUnit.MONTHS;
043import static org.threeten.bp.temporal.ChronoUnit.NANOS;
044import static org.threeten.bp.temporal.ChronoUnit.SECONDS;
045import static org.threeten.bp.temporal.ChronoUnit.WEEKS;
046import static org.threeten.bp.temporal.ChronoUnit.YEARS;
047
048import org.threeten.bp.DayOfWeek;
049import org.threeten.bp.Instant;
050import org.threeten.bp.Year;
051import org.threeten.bp.ZoneOffset;
052import org.threeten.bp.format.DateTimeBuilder;
053
054/**
055 * A standard set of fields.
056 * <p>
057 * This set of fields provide field-based access to manipulate a date, time or date-time.
058 * The standard set of fields can be extended by implementing {@link TemporalField}.
059 * <p>
060 * These fields are intended to be applicable in multiple calendar systems.
061 * For example, most non-ISO calendar systems define dates as a year, month and day,
062 * just with slightly different rules.
063 * The documentation of each field explains how it operates.
064 *
065 * <h3>Specification for implementors</h3>
066 * This is a final, immutable and thread-safe enum.
067 */
068public enum ChronoField implements TemporalField {
069
070    /**
071     * The nano-of-second.
072     * <p>
073     * This counts the nanosecond within the second, from 0 to 999,999,999.
074     * This field has the same meaning for all calendar systems.
075     * <p>
076     * This field is used to represent the nano-of-second handling any fraction of the second.
077     * Implementations of {@code TemporalAccessor} should provide a value for this field if
078     * they can return a value for {@link #SECOND_OF_MINUTE}, {@link #SECOND_OF_DAY} or
079     * {@link #INSTANT_SECONDS} filling unknown precision with zero.
080     * <p>
081     * When this field is used for setting a value, it should set as much precision as the
082     * object stores, using integer division to remove excess precision.
083     * For example, if the {@code TemporalAccessor} stores time to millisecond precision,
084     * then the nano-of-second must be divided by 1,000,000 before replacing the milli-of-second.
085     */
086    NANO_OF_SECOND("NanoOfSecond", NANOS, SECONDS, ValueRange.of(0, 999_999_999)),
087    /**
088     * The nano-of-day.
089     * <p>
090     * This counts the nanosecond within the day, from 0 to (24 * 60 * 60 * 1,000,000,000) - 1.
091     * This field has the same meaning for all calendar systems.
092     * <p>
093     * This field is used to represent the nano-of-day handling any fraction of the second.
094     * Implementations of {@code TemporalAccessor} should provide a value for this field if
095     * they can return a value for {@link #SECOND_OF_DAY} filling unknown precision with zero.
096     */
097    NANO_OF_DAY("NanoOfDay", NANOS, DAYS, ValueRange.of(0, 86400L * 1000_000_000L - 1)),
098    /**
099     * The micro-of-second.
100     * <p>
101     * This counts the microsecond within the second, from 0 to 999,999.
102     * This field has the same meaning for all calendar systems.
103     * <p>
104     * This field is used to represent the micro-of-second handling any fraction of the second.
105     * Implementations of {@code TemporalAccessor} should provide a value for this field if
106     * they can return a value for {@link #SECOND_OF_MINUTE}, {@link #SECOND_OF_DAY} or
107     * {@link #INSTANT_SECONDS} filling unknown precision with zero.
108     * <p>
109     * When this field is used for setting a value, it should behave in the same way as
110     * setting {@link #NANO_OF_SECOND} with the value multiplied by 1,000.
111     */
112    MICRO_OF_SECOND("MicroOfSecond", MICROS, SECONDS, ValueRange.of(0, 999_999)),
113    /**
114     * The micro-of-day.
115     * <p>
116     * This counts the microsecond within the day, from 0 to (24 * 60 * 60 * 1,000,000) - 1.
117     * This field has the same meaning for all calendar systems.
118     * <p>
119     * This field is used to represent the micro-of-day handling any fraction of the second.
120     * Implementations of {@code TemporalAccessor} should provide a value for this field if
121     * they can return a value for {@link #SECOND_OF_DAY} filling unknown precision with zero.
122     * <p>
123     * When this field is used for setting a value, it should behave in the same way as
124     * setting {@link #NANO_OF_DAY} with the value multiplied by 1,000.
125     */
126    MICRO_OF_DAY("MicroOfDay", MICROS, DAYS, ValueRange.of(0, 86400L * 1000_000L - 1)),
127    /**
128     * The milli-of-second.
129     * <p>
130     * This counts the millisecond within the second, from 0 to 999.
131     * This field has the same meaning for all calendar systems.
132     * <p>
133     * This field is used to represent the milli-of-second handling any fraction of the second.
134     * Implementations of {@code TemporalAccessor} should provide a value for this field if
135     * they can return a value for {@link #SECOND_OF_MINUTE}, {@link #SECOND_OF_DAY} or
136     * {@link #INSTANT_SECONDS} filling unknown precision with zero.
137     * <p>
138     * When this field is used for setting a value, it should behave in the same way as
139     * setting {@link #NANO_OF_SECOND} with the value multiplied by 1,000,000.
140     */
141    MILLI_OF_SECOND("MilliOfSecond", MILLIS, SECONDS, ValueRange.of(0, 999)),
142    /**
143     * The milli-of-day.
144     * <p>
145     * This counts the millisecond within the day, from 0 to (24 * 60 * 60 * 1,000) - 1.
146     * This field has the same meaning for all calendar systems.
147     * <p>
148     * This field is used to represent the milli-of-day handling any fraction of the second.
149     * Implementations of {@code TemporalAccessor} should provide a value for this field if
150     * they can return a value for {@link #SECOND_OF_DAY} filling unknown precision with zero.
151     * <p>
152     * When this field is used for setting a value, it should behave in the same way as
153     * setting {@link #NANO_OF_DAY} with the value multiplied by 1,000,000.
154     */
155    MILLI_OF_DAY("MilliOfDay", MILLIS, DAYS, ValueRange.of(0, 86400L * 1000L - 1)),
156    /**
157     * The second-of-minute.
158     * <p>
159     * This counts the second within the minute, from 0 to 59.
160     * This field has the same meaning for all calendar systems.
161     */
162    SECOND_OF_MINUTE("SecondOfMinute", SECONDS, MINUTES, ValueRange.of(0, 59)),
163    /**
164     * The second-of-day.
165     * <p>
166     * This counts the second within the day, from 0 to (24 * 60 * 60) - 1.
167     * This field has the same meaning for all calendar systems.
168     */
169    SECOND_OF_DAY("SecondOfDay", SECONDS, DAYS, ValueRange.of(0, 86400L - 1)),
170    /**
171     * The minute-of-hour.
172     * <p>
173     * This counts the minute within the hour, from 0 to 59.
174     * This field has the same meaning for all calendar systems.
175     */
176    MINUTE_OF_HOUR("MinuteOfHour", MINUTES, HOURS, ValueRange.of(0, 59)),
177    /**
178     * The minute-of-day.
179     * <p>
180     * This counts the minute within the day, from 0 to (24 * 60) - 1.
181     * This field has the same meaning for all calendar systems.
182     */
183    MINUTE_OF_DAY("MinuteOfDay", MINUTES, DAYS, ValueRange.of(0, (24 * 60) - 1)),
184    /**
185     * The hour-of-am-pm.
186     * <p>
187     * This counts the hour within the AM/PM, from 0 to 11.
188     * This is the hour that would be observed on a standard 12-hour digital clock.
189     * This field has the same meaning for all calendar systems.
190     */
191    HOUR_OF_AMPM("HourOfAmPm", HOURS, HALF_DAYS, ValueRange.of(0, 11)),
192    /**
193     * The clock-hour-of-am-pm.
194     * <p>
195     * This counts the hour within the AM/PM, from 1 to 12.
196     * This is the hour that would be observed on a standard 12-hour analog wall clock.
197     * This field has the same meaning for all calendar systems.
198     */
199    CLOCK_HOUR_OF_AMPM("ClockHourOfAmPm", HOURS, HALF_DAYS, ValueRange.of(1, 12)),
200    /**
201     * The hour-of-day.
202     * <p>
203     * This counts the hour within the day, from 0 to 23.
204     * This is the hour that would be observed on a standard 24-hour digital clock.
205     * This field has the same meaning for all calendar systems.
206     */
207    HOUR_OF_DAY("HourOfDay", HOURS, DAYS, ValueRange.of(0, 23)),
208    /**
209     * The clock-hour-of-day.
210     * <p>
211     * This counts the hour within the AM/PM, from 1 to 24.
212     * This is the hour that would be observed on a 24-hour analog wall clock.
213     * This field has the same meaning for all calendar systems.
214     */
215    CLOCK_HOUR_OF_DAY("ClockHourOfDay", HOURS, DAYS, ValueRange.of(1, 24)),
216    /**
217     * The am-pm-of-day.
218     * <p>
219     * This counts the AM/PM within the day, from 0 (AM) to 1 (PM).
220     * This field has the same meaning for all calendar systems.
221     */
222    AMPM_OF_DAY("AmPmOfDay", HALF_DAYS, DAYS, ValueRange.of(0, 1)),
223    /**
224     * The day-of-week, such as Tuesday.
225     * <p>
226     * This represents the standard concept of the day of the week.
227     * In the default ISO calendar system, this has values from Monday (1) to Sunday (7).
228     * The {@link DayOfWeek} class can be used to interpret the result.
229     * <p>
230     * Most non-ISO calendar systems also define a seven day week that aligns with ISO.
231     * Those calendar systems must also use the same numbering system, from Monday (1) to
232     * Sunday (7), which allows {@code DayOfWeek} to be used.
233     * <p>
234     * Calendar systems that do not have a standard seven day week should implement this field
235     * if they have a similar concept of named or numbered days within a period similar
236     * to a week. It is recommended that the numbering starts from 1.
237     */
238    DAY_OF_WEEK("DayOfWeek", DAYS, WEEKS, ValueRange.of(1, 7)),
239    /**
240     * The aligned day-of-week within a month.
241     * <p>
242     * This represents concept of the count of days within the period of a week
243     * where the weeks are aligned to the start of the month.
244     * This field is typically used with {@link #ALIGNED_WEEK_OF_MONTH}.
245     * <p>
246     * For example, in a calendar systems with a seven day week, the first aligned-week-of-month
247     * starts on day-of-month 1, the second aligned-week starts on day-of-month 8, and so on.
248     * Within each of these aligned-weeks, the days are numbered from 1 to 7 and returned
249     * as the value of this field.
250     * As such, day-of-month 1 to 7 will have aligned-day-of-week values from 1 to 7.
251     * And day-of-month 8 to 14 will repeat this with aligned-day-of-week values from 1 to 7.
252     * <p>
253     * Calendar systems that do not have a seven day week should typically implement this
254     * field in the same way, but using the alternate week length.
255     */
256    ALIGNED_DAY_OF_WEEK_IN_MONTH("AlignedDayOfWeekInMonth", DAYS, WEEKS, ValueRange.of(1, 7)),
257    /**
258     * The aligned day-of-week within a year.
259     * <p>
260     * This represents concept of the count of days within the period of a week
261     * where the weeks are aligned to the start of the year.
262     * This field is typically used with {@link #ALIGNED_WEEK_OF_YEAR}.
263     * <p>
264     * For example, in a calendar systems with a seven day week, the first aligned-week-of-year
265     * starts on day-of-year 1, the second aligned-week starts on day-of-year 8, and so on.
266     * Within each of these aligned-weeks, the days are numbered from 1 to 7 and returned
267     * as the value of this field.
268     * As such, day-of-year 1 to 7 will have aligned-day-of-week values from 1 to 7.
269     * And day-of-year 8 to 14 will repeat this with aligned-day-of-week values from 1 to 7.
270     * <p>
271     * Calendar systems that do not have a seven day week should typically implement this
272     * field in the same way, but using the alternate week length.
273     */
274    ALIGNED_DAY_OF_WEEK_IN_YEAR("AlignedDayOfWeekInYear", DAYS, WEEKS, ValueRange.of(1, 7)),
275    /**
276     * The day-of-month.
277     * <p>
278     * This represents the concept of the day within the month.
279     * In the default ISO calendar system, this has values from 1 to 31 in most months.
280     * April, June, September, November have days from 1 to 30, while February has days
281     * from 1 to 28, or 29 in a leap year.
282     * <p>
283     * Non-ISO calendar systems should implement this field using the most recognized
284     * day-of-month values for users of the calendar system.
285     * Normally, this is a count of days from 1 to the length of the month.
286     */
287    DAY_OF_MONTH("DayOfMonth", DAYS, MONTHS, ValueRange.of(1, 28, 31)),
288    /**
289     * The day-of-year.
290     * <p>
291     * This represents the concept of the day within the year.
292     * In the default ISO calendar system, this has values from 1 to 365 in standard
293     * years and 1 to 366 in leap years.
294     * <p>
295     * Non-ISO calendar systems should implement this field using the most recognized
296     * day-of-year values for users of the calendar system.
297     * Normally, this is a count of days from 1 to the length of the year.
298     */
299    DAY_OF_YEAR("DayOfYear", DAYS, YEARS, ValueRange.of(1, 365, 366)),
300    /**
301     * The epoch-day, based on the Java epoch of 1970-01-01 (ISO).
302     * <p>
303     * This field is the sequential count of days where 1970-01-01 (ISO) is zero.
304     * Note that this uses the <i>local</i> time-line, ignoring offset and time-zone.
305     * <p>
306     * This field is strictly defined to have the same meaning in all calendar systems.
307     * This is necessary to ensure interoperation between calendars.
308     */
309    EPOCH_DAY("EpochDay", DAYS, FOREVER, ValueRange.of((long) (Year.MIN_VALUE * 365.25), (long) (Year.MAX_VALUE * 365.25))),
310    /**
311     * The aligned week within a month.
312     * <p>
313     * This represents concept of the count of weeks within the period of a month
314     * where the weeks are aligned to the start of the month.
315     * This field is typically used with {@link #ALIGNED_DAY_OF_WEEK_IN_MONTH}.
316     * <p>
317     * For example, in a calendar systems with a seven day week, the first aligned-week-of-month
318     * starts on day-of-month 1, the second aligned-week starts on day-of-month 8, and so on.
319     * Thus, day-of-month values 1 to 7 are in aligned-week 1, while day-of-month values
320     * 8 to 14 are in aligned-week 2, and so on.
321     * <p>
322     * Calendar systems that do not have a seven day week should typically implement this
323     * field in the same way, but using the alternate week length.
324     */
325    ALIGNED_WEEK_OF_MONTH("AlignedWeekOfMonth", WEEKS, MONTHS, ValueRange.of(1, 4, 5)),
326    /**
327     * The aligned week within a year.
328     * <p>
329     * This represents concept of the count of weeks within the period of a year
330     * where the weeks are aligned to the start of the year.
331     * This field is typically used with {@link #ALIGNED_DAY_OF_WEEK_IN_YEAR}.
332     * <p>
333     * For example, in a calendar systems with a seven day week, the first aligned-week-of-year
334     * starts on day-of-year 1, the second aligned-week starts on day-of-year 8, and so on.
335     * Thus, day-of-year values 1 to 7 are in aligned-week 1, while day-of-year values
336     * 8 to 14 are in aligned-week 2, and so on.
337     * <p>
338     * Calendar systems that do not have a seven day week should typically implement this
339     * field in the same way, but using the alternate week length.
340     */
341    ALIGNED_WEEK_OF_YEAR("AlignedWeekOfYear", WEEKS, YEARS, ValueRange.of(1, 53)),
342    /**
343     * The month-of-year, such as March.
344     * <p>
345     * This represents the concept of the month within the year.
346     * In the default ISO calendar system, this has values from January (1) to December (12).
347     * <p>
348     * Non-ISO calendar systems should implement this field using the most recognized
349     * month-of-year values for users of the calendar system.
350     * Normally, this is a count of months starting from 1.
351     */
352    MONTH_OF_YEAR("MonthOfYear", MONTHS, YEARS, ValueRange.of(1, 12)),
353    /**
354     * The epoch-month based on the Java epoch of 1970-01-01.
355     * <p>
356     * This field is the sequential count of months where January 1970 (ISO) is zero.
357     * Note that this uses the <i>local</i> time-line, ignoring offset and time-zone.
358     * <p>
359     * Non-ISO calendar systems should also implement this field to represent a sequential
360     * count of months. It is recommended to define zero as the month of 1970-01-01 (ISO).
361     */
362    EPOCH_MONTH("EpochMonth", MONTHS, FOREVER, ValueRange.of((Year.MIN_VALUE - 1970L) * 12, (Year.MAX_VALUE - 1970L) * 12L - 1L)),
363    /**
364     * The year within the era.
365     * <p>
366     * This represents the concept of the year within the era.
367     * This field is typically used with {@link #ERA}.
368     * <p>
369     * The standard mental model for a date is based on three concepts - year, month and day.
370     * These map onto the {@code YEAR}, {@code MONTH_OF_YEAR} and {@code DAY_OF_MONTH} fields.
371     * Note that there is no reference to eras.
372     * The full model for a date requires four concepts - era, year, month and day. These map onto
373     * the {@code ERA}, {@code YEAR_OF_ERA}, {@code MONTH_OF_YEAR} and {@code DAY_OF_MONTH} fields.
374     * Whether this field or {@code YEAR} is used depends on which mental model is being used.
375     * See {@link ChronoLocalDate} for more discussion on this topic.
376     * <p>
377     * In the default ISO calendar system, there are two eras defined, 'BCE' and 'CE'.
378     * The era 'CE' is the one currently in use and year-of-era runs from 1 to the maximum value.
379     * The era 'BCE' is the previous era, and the year-of-era runs backwards.
380     * <p>
381     * For example, subtracting a year each time yield the following:<br>
382     * - year-proleptic 2  = 'CE' year-of-era 2<br>
383     * - year-proleptic 1  = 'CE' year-of-era 1<br>
384     * - year-proleptic 0  = 'BCE' year-of-era 1<br>
385     * - year-proleptic -1 = 'BCE' year-of-era 2<br>
386     * <p>
387     * Note that the ISO-8601 standard does not actually define eras.
388     * Note also that the ISO eras do not align with the well-known AD/BC eras due to the
389     * change between the Julian and Gregorian calendar systems.
390     * <p>
391     * Non-ISO calendar systems should implement this field using the most recognized
392     * year-of-era value for users of the calendar system.
393     * Since most calendar systems have only two eras, the year-of-era numbering approach
394     * will typically be the same as that used by the ISO calendar system.
395     * The year-of-era value should typically always be positive, however this is not required.
396     */
397    YEAR_OF_ERA("YearOfEra", YEARS, FOREVER, ValueRange.of(1, Year.MAX_VALUE, Year.MAX_VALUE + 1)),
398    /**
399     * The proleptic year, such as 2012.
400     * <p>
401     * This represents the concept of the year, counting sequentially and using negative numbers.
402     * The proleptic year is not interpreted in terms of the era.
403     * See {@link #YEAR_OF_ERA} for an example showing the mapping from proleptic year to year-of-era.
404     * <p>
405     * The standard mental model for a date is based on three concepts - year, month and day.
406     * These map onto the {@code YEAR}, {@code MONTH_OF_YEAR} and {@code DAY_OF_MONTH} fields.
407     * Note that there is no reference to eras.
408     * The full model for a date requires four concepts - era, year, month and day. These map onto
409     * the {@code ERA}, {@code YEAR_OF_ERA}, {@code MONTH_OF_YEAR} and {@code DAY_OF_MONTH} fields.
410     * Whether this field or {@code YEAR_OF_ERA} is used depends on which mental model is being used.
411     * See {@link ChronoLocalDate} for more discussion on this topic.
412     * <p>
413     * Non-ISO calendar systems should implement this field as follows.
414     * If the calendar system has only two eras, before and after a fixed date, then the
415     * proleptic-year value must be the same as the year-of-era value for the later era,
416     * and increasingly negative for the earlier era.
417     * If the calendar system has more than two eras, then the proleptic-year value may be
418     * defined with any appropriate value, although defining it to be the same as ISO may be
419     * the best option.
420     */
421    YEAR("Year", YEARS, FOREVER, ValueRange.of(Year.MIN_VALUE, Year.MAX_VALUE)),
422    /**
423     * The era.
424     * <p>
425     * This represents the concept of the era, which is the largest division of the time-line.
426     * This field is typically used with {@link #YEAR_OF_ERA}.
427     * <p>
428     * In the default ISO calendar system, there are two eras defined, 'BCE' and 'CE'.
429     * The era 'CE' is the one currently in use and year-of-era runs from 1 to the maximum value.
430     * The era 'BCE' is the previous era, and the year-of-era runs backwards.
431     * See {@link #YEAR_OF_ERA} for a full example.
432     * <p>
433     * Non-ISO calendar systems should implement this field to define eras.
434     * The value of the era that was active on 1970-01-01 (ISO) must be assigned the value 1.
435     * Earlier eras must have sequentially smaller values.
436     * Later eras must have sequentially larger values,
437     */
438    ERA("Era", ERAS, FOREVER, ValueRange.of(0, 1)),
439    /**
440     * The instant epoch-seconds.
441     * <p>
442     * This represents the concept of the sequential count of seconds where
443     * 1970-01-01T00:00Z (ISO) is zero.
444     * This field may be used with {@link #NANO_OF_DAY} to represent the fraction of the day.
445     * <p>
446     * An {@link Instant} represents an instantaneous point on the time-line.
447     * On their own they have no elements which allow a local date-time to be obtained.
448     * Only when paired with an offset or time-zone can the local date or time be found.
449     * This field allows the seconds part of the instant to be queried.
450     * <p>
451     * This field is strictly defined to have the same meaning in all calendar systems.
452     * This is necessary to ensure interoperation between calendars.
453     */
454    INSTANT_SECONDS("InstantSeconds", SECONDS, FOREVER, ValueRange.of(Long.MIN_VALUE, Long.MAX_VALUE)),
455    /**
456     * The offset from UTC/Greenwich.
457     * <p>
458     * This represents the concept of the offset in seconds of local time from UTC/Greenwich.
459     * <p>
460     * A {@link ZoneOffset} represents the period of time that local time differs from UTC/Greenwich.
461     * This is usually a fixed number of hours and minutes.
462     * It is equivalent to the {@link ZoneOffset#getTotalSeconds() total amount} of the offset in seconds.
463     * For example, during the winter Paris has an offset of {@code +01:00}, which is 3600 seconds.
464     * <p>
465     * This field is strictly defined to have the same meaning in all calendar systems.
466     * This is necessary to ensure interoperation between calendars.
467     */
468    OFFSET_SECONDS("OffsetSeconds", SECONDS, FOREVER, ValueRange.of(-18 * 3600, 18 * 3600));
469
470    private final String name;
471    private final TemporalUnit baseUnit;
472    private final TemporalUnit rangeUnit;
473    private final ValueRange range;
474
475    private ChronoField(String name, TemporalUnit baseUnit, TemporalUnit rangeUnit, ValueRange range) {
476        this.name = name;
477        this.baseUnit = baseUnit;
478        this.rangeUnit = rangeUnit;
479        this.range = range;
480    }
481
482    //-----------------------------------------------------------------------
483    @Override
484    public String getName() {
485        return name;
486    }
487
488    @Override
489    public TemporalUnit getBaseUnit() {
490        return baseUnit;
491    }
492
493    @Override
494    public TemporalUnit getRangeUnit() {
495        return rangeUnit;
496    }
497
498    @Override
499    public ValueRange range() {
500        return range;
501    }
502
503    //-----------------------------------------------------------------------
504    /**
505     * Checks if this field represents a component of a date.
506     *
507     * @return true if it is a component of a date
508     */
509    public boolean isDateField() {
510        return ordinal() >= DAY_OF_WEEK.ordinal() && ordinal() <= ERA.ordinal();
511    }
512
513    /**
514     * Checks if this field represents a component of a time.
515     *
516     * @return true if it is a component of a time
517     */
518    public boolean isTimeField() {
519        return ordinal() < DAY_OF_WEEK.ordinal();
520    }
521
522    //-----------------------------------------------------------------------
523    /**
524     * Checks that the specified value is valid for this field.
525     * <p>
526     * This validates that the value is within the outer range of valid values
527     * returned by {@link #range()}.
528     *
529     * @param value  the value to check
530     * @return the value that was passed in
531     */
532    public long checkValidValue(long value) {
533        return range().checkValidValue(value, this);
534    }
535
536    /**
537     * Checks that the specified value is valid and fits in an {@code int}.
538     * <p>
539     * This validates that the value is within the outer range of valid values
540     * returned by {@link #range()}.
541     * It also checks that all valid values are within the bounds of an {@code int}.
542     *
543     * @param value  the value to check
544     * @return the value that was passed in
545     */
546    public int checkValidIntValue(long value) {
547        return range().checkValidIntValue(value, this);
548    }
549
550    //-------------------------------------------------------------------------
551    @Override
552    public int compare(TemporalAccessor temporal1, TemporalAccessor temporal2) {
553        return Long.compare(temporal1.getLong(this), temporal2.getLong(this));
554    }
555
556    //-----------------------------------------------------------------------
557    @Override
558    public boolean doIsSupported(TemporalAccessor temporal) {
559        return temporal.isSupported(this);
560    }
561
562    @Override
563    public ValueRange doRange(TemporalAccessor temporal) {
564        return temporal.range(this);
565    }
566
567    @Override
568    public long doGet(TemporalAccessor temporal) {
569        return temporal.getLong(this);
570    }
571
572    @Override
573    public <R extends Temporal> R doWith(R temporal, long newValue) {
574        return (R) temporal.with(this, newValue);
575    }
576
577    //-----------------------------------------------------------------------
578    @Override
579    public boolean resolve(DateTimeBuilder builder, long value) {
580        return false;  // resolve implemented in builder
581    }
582
583    //-----------------------------------------------------------------------
584    @Override
585    public String toString() {
586        return getName();
587    }
588
589}