jdk/src/share/classes/java/time/temporal/ChronoField.java
changeset 17474 8c100beabcc0
parent 16852 60207b2b4b42
child 19030 32f129cb6351
equal deleted inserted replaced
17473:35cd9b3a98ff 17474:8c100beabcc0
    91  * These fields are intended to be applicable in multiple calendar systems.
    91  * These fields are intended to be applicable in multiple calendar systems.
    92  * For example, most non-ISO calendar systems define dates as a year, month and day,
    92  * For example, most non-ISO calendar systems define dates as a year, month and day,
    93  * just with slightly different rules.
    93  * just with slightly different rules.
    94  * The documentation of each field explains how it operates.
    94  * The documentation of each field explains how it operates.
    95  *
    95  *
    96  * <h3>Specification for implementors</h3>
    96  * @implSpec
    97  * This is a final, immutable and thread-safe enum.
    97  * This is a final, immutable and thread-safe enum.
    98  *
    98  *
    99  * @since 1.8
    99  * @since 1.8
   100  */
   100  */
   101 public enum ChronoField implements TemporalField {
   101 public enum ChronoField implements TemporalField {
   113      * <p>
   113      * <p>
   114      * When this field is used for setting a value, it should set as much precision as the
   114      * When this field is used for setting a value, it should set as much precision as the
   115      * object stores, using integer division to remove excess precision.
   115      * object stores, using integer division to remove excess precision.
   116      * For example, if the {@code TemporalAccessor} stores time to millisecond precision,
   116      * For example, if the {@code TemporalAccessor} stores time to millisecond precision,
   117      * then the nano-of-second must be divided by 1,000,000 before replacing the milli-of-second.
   117      * then the nano-of-second must be divided by 1,000,000 before replacing the milli-of-second.
       
   118      * <p>
       
   119      * When parsing this field it behaves equivalent to the following:
       
   120      * The value is validated in strict and smart mode but not in lenient mode.
       
   121      * The field is resolved in combination with {@code MILLI_OF_SECOND} and {@code MICRO_OF_SECOND}.
   118      */
   122      */
   119     NANO_OF_SECOND("NanoOfSecond", NANOS, SECONDS, ValueRange.of(0, 999_999_999)),
   123     NANO_OF_SECOND("NanoOfSecond", NANOS, SECONDS, ValueRange.of(0, 999_999_999)),
   120     /**
   124     /**
   121      * The nano-of-day.
   125      * The nano-of-day.
   122      * <p>
   126      * <p>
   124      * This field has the same meaning for all calendar systems.
   128      * This field has the same meaning for all calendar systems.
   125      * <p>
   129      * <p>
   126      * This field is used to represent the nano-of-day handling any fraction of the second.
   130      * This field is used to represent the nano-of-day handling any fraction of the second.
   127      * Implementations of {@code TemporalAccessor} should provide a value for this field if
   131      * Implementations of {@code TemporalAccessor} should provide a value for this field if
   128      * they can return a value for {@link #SECOND_OF_DAY} filling unknown precision with zero.
   132      * they can return a value for {@link #SECOND_OF_DAY} filling unknown precision with zero.
       
   133      * <p>
       
   134      * When parsing this field it behaves equivalent to the following:
       
   135      * The value is validated in strict and smart mode but not in lenient mode.
       
   136      * The value is split to form {@code NANO_OF_SECOND}, {@code SECOND_OF_MINUTE},
       
   137      * {@code MINUTE_OF_HOUR} and {@code HOUR_OF_DAY} fields.
   129      */
   138      */
   130     NANO_OF_DAY("NanoOfDay", NANOS, DAYS, ValueRange.of(0, 86400L * 1000_000_000L - 1)),
   139     NANO_OF_DAY("NanoOfDay", NANOS, DAYS, ValueRange.of(0, 86400L * 1000_000_000L - 1)),
   131     /**
   140     /**
   132      * The micro-of-second.
   141      * The micro-of-second.
   133      * <p>
   142      * <p>
   139      * they can return a value for {@link #SECOND_OF_MINUTE}, {@link #SECOND_OF_DAY} or
   148      * they can return a value for {@link #SECOND_OF_MINUTE}, {@link #SECOND_OF_DAY} or
   140      * {@link #INSTANT_SECONDS} filling unknown precision with zero.
   149      * {@link #INSTANT_SECONDS} filling unknown precision with zero.
   141      * <p>
   150      * <p>
   142      * When this field is used for setting a value, it should behave in the same way as
   151      * When this field is used for setting a value, it should behave in the same way as
   143      * setting {@link #NANO_OF_SECOND} with the value multiplied by 1,000.
   152      * setting {@link #NANO_OF_SECOND} with the value multiplied by 1,000.
       
   153      * <p>
       
   154      * When parsing this field it behaves equivalent to the following:
       
   155      * The value is validated in strict and smart mode but not in lenient mode.
       
   156      * The field is resolved in combination with {@code MILLI_OF_SECOND} to produce
       
   157      * {@code NANO_OF_SECOND}.
   144      */
   158      */
   145     MICRO_OF_SECOND("MicroOfSecond", MICROS, SECONDS, ValueRange.of(0, 999_999)),
   159     MICRO_OF_SECOND("MicroOfSecond", MICROS, SECONDS, ValueRange.of(0, 999_999)),
   146     /**
   160     /**
   147      * The micro-of-day.
   161      * The micro-of-day.
   148      * <p>
   162      * <p>
   153      * Implementations of {@code TemporalAccessor} should provide a value for this field if
   167      * Implementations of {@code TemporalAccessor} should provide a value for this field if
   154      * they can return a value for {@link #SECOND_OF_DAY} filling unknown precision with zero.
   168      * they can return a value for {@link #SECOND_OF_DAY} filling unknown precision with zero.
   155      * <p>
   169      * <p>
   156      * When this field is used for setting a value, it should behave in the same way as
   170      * When this field is used for setting a value, it should behave in the same way as
   157      * setting {@link #NANO_OF_DAY} with the value multiplied by 1,000.
   171      * setting {@link #NANO_OF_DAY} with the value multiplied by 1,000.
       
   172      * <p>
       
   173      * When parsing this field it behaves equivalent to the following:
       
   174      * The value is validated in strict and smart mode but not in lenient mode.
       
   175      * The value is split to form {@code MICRO_OF_SECOND}, {@code SECOND_OF_MINUTE},
       
   176      * {@code MINUTE_OF_HOUR} and {@code HOUR_OF_DAY} fields.
   158      */
   177      */
   159     MICRO_OF_DAY("MicroOfDay", MICROS, DAYS, ValueRange.of(0, 86400L * 1000_000L - 1)),
   178     MICRO_OF_DAY("MicroOfDay", MICROS, DAYS, ValueRange.of(0, 86400L * 1000_000L - 1)),
   160     /**
   179     /**
   161      * The milli-of-second.
   180      * The milli-of-second.
   162      * <p>
   181      * <p>
   168      * they can return a value for {@link #SECOND_OF_MINUTE}, {@link #SECOND_OF_DAY} or
   187      * they can return a value for {@link #SECOND_OF_MINUTE}, {@link #SECOND_OF_DAY} or
   169      * {@link #INSTANT_SECONDS} filling unknown precision with zero.
   188      * {@link #INSTANT_SECONDS} filling unknown precision with zero.
   170      * <p>
   189      * <p>
   171      * When this field is used for setting a value, it should behave in the same way as
   190      * When this field is used for setting a value, it should behave in the same way as
   172      * setting {@link #NANO_OF_SECOND} with the value multiplied by 1,000,000.
   191      * setting {@link #NANO_OF_SECOND} with the value multiplied by 1,000,000.
       
   192      * <p>
       
   193      * When parsing this field it behaves equivalent to the following:
       
   194      * The value is validated in strict and smart mode but not in lenient mode.
       
   195      * The field is resolved in combination with {@code MICRO_OF_SECOND} to produce
       
   196      * {@code NANO_OF_SECOND}.
   173      */
   197      */
   174     MILLI_OF_SECOND("MilliOfSecond", MILLIS, SECONDS, ValueRange.of(0, 999)),
   198     MILLI_OF_SECOND("MilliOfSecond", MILLIS, SECONDS, ValueRange.of(0, 999)),
   175     /**
   199     /**
   176      * The milli-of-day.
   200      * The milli-of-day.
   177      * <p>
   201      * <p>
   182      * Implementations of {@code TemporalAccessor} should provide a value for this field if
   206      * Implementations of {@code TemporalAccessor} should provide a value for this field if
   183      * they can return a value for {@link #SECOND_OF_DAY} filling unknown precision with zero.
   207      * they can return a value for {@link #SECOND_OF_DAY} filling unknown precision with zero.
   184      * <p>
   208      * <p>
   185      * When this field is used for setting a value, it should behave in the same way as
   209      * When this field is used for setting a value, it should behave in the same way as
   186      * setting {@link #NANO_OF_DAY} with the value multiplied by 1,000,000.
   210      * setting {@link #NANO_OF_DAY} with the value multiplied by 1,000,000.
       
   211      * <p>
       
   212      * When parsing this field it behaves equivalent to the following:
       
   213      * The value is validated in strict and smart mode but not in lenient mode.
       
   214      * The value is split to form {@code MILLI_OF_SECOND}, {@code SECOND_OF_MINUTE},
       
   215      * {@code MINUTE_OF_HOUR} and {@code HOUR_OF_DAY} fields.
   187      */
   216      */
   188     MILLI_OF_DAY("MilliOfDay", MILLIS, DAYS, ValueRange.of(0, 86400L * 1000L - 1)),
   217     MILLI_OF_DAY("MilliOfDay", MILLIS, DAYS, ValueRange.of(0, 86400L * 1000L - 1)),
   189     /**
   218     /**
   190      * The second-of-minute.
   219      * The second-of-minute.
   191      * <p>
   220      * <p>
   192      * This counts the second within the minute, from 0 to 59.
   221      * This counts the second within the minute, from 0 to 59.
   193      * This field has the same meaning for all calendar systems.
   222      * This field has the same meaning for all calendar systems.
       
   223      * <p>
       
   224      * When parsing this field it behaves equivalent to the following:
       
   225      * The value is validated in strict and smart mode but not in lenient mode.
   194      */
   226      */
   195     SECOND_OF_MINUTE("SecondOfMinute", SECONDS, MINUTES, ValueRange.of(0, 59), "second"),
   227     SECOND_OF_MINUTE("SecondOfMinute", SECONDS, MINUTES, ValueRange.of(0, 59), "second"),
   196     /**
   228     /**
   197      * The second-of-day.
   229      * The second-of-day.
   198      * <p>
   230      * <p>
   199      * This counts the second within the day, from 0 to (24 * 60 * 60) - 1.
   231      * This counts the second within the day, from 0 to (24 * 60 * 60) - 1.
   200      * This field has the same meaning for all calendar systems.
   232      * This field has the same meaning for all calendar systems.
       
   233      * <p>
       
   234      * When parsing this field it behaves equivalent to the following:
       
   235      * The value is validated in strict and smart mode but not in lenient mode.
       
   236      * The value is split to form {@code SECOND_OF_MINUTE}, {@code MINUTE_OF_HOUR}
       
   237      * and {@code HOUR_OF_DAY} fields.
   201      */
   238      */
   202     SECOND_OF_DAY("SecondOfDay", SECONDS, DAYS, ValueRange.of(0, 86400L - 1)),
   239     SECOND_OF_DAY("SecondOfDay", SECONDS, DAYS, ValueRange.of(0, 86400L - 1)),
   203     /**
   240     /**
   204      * The minute-of-hour.
   241      * The minute-of-hour.
   205      * <p>
   242      * <p>
   206      * This counts the minute within the hour, from 0 to 59.
   243      * This counts the minute within the hour, from 0 to 59.
   207      * This field has the same meaning for all calendar systems.
   244      * This field has the same meaning for all calendar systems.
       
   245      * <p>
       
   246      * When parsing this field it behaves equivalent to the following:
       
   247      * The value is validated in strict and smart mode but not in lenient mode.
   208      */
   248      */
   209     MINUTE_OF_HOUR("MinuteOfHour", MINUTES, HOURS, ValueRange.of(0, 59), "minute"),
   249     MINUTE_OF_HOUR("MinuteOfHour", MINUTES, HOURS, ValueRange.of(0, 59), "minute"),
   210     /**
   250     /**
   211      * The minute-of-day.
   251      * The minute-of-day.
   212      * <p>
   252      * <p>
   213      * This counts the minute within the day, from 0 to (24 * 60) - 1.
   253      * This counts the minute within the day, from 0 to (24 * 60) - 1.
   214      * This field has the same meaning for all calendar systems.
   254      * This field has the same meaning for all calendar systems.
       
   255      * <p>
       
   256      * When parsing this field it behaves equivalent to the following:
       
   257      * The value is validated in strict and smart mode but not in lenient mode.
       
   258      * The value is split to form {@code MINUTE_OF_HOUR} and {@code HOUR_OF_DAY} fields.
   215      */
   259      */
   216     MINUTE_OF_DAY("MinuteOfDay", MINUTES, DAYS, ValueRange.of(0, (24 * 60) - 1)),
   260     MINUTE_OF_DAY("MinuteOfDay", MINUTES, DAYS, ValueRange.of(0, (24 * 60) - 1)),
   217     /**
   261     /**
   218      * The hour-of-am-pm.
   262      * The hour-of-am-pm.
   219      * <p>
   263      * <p>
   220      * This counts the hour within the AM/PM, from 0 to 11.
   264      * This counts the hour within the AM/PM, from 0 to 11.
   221      * This is the hour that would be observed on a standard 12-hour digital clock.
   265      * This is the hour that would be observed on a standard 12-hour digital clock.
   222      * This field has the same meaning for all calendar systems.
   266      * This field has the same meaning for all calendar systems.
       
   267      * <p>
       
   268      * When parsing this field it behaves equivalent to the following:
       
   269      * The value is validated from 0 to 11 in strict and smart mode.
       
   270      * In lenient mode the value is not validated. It is combined with
       
   271      * {@code AMPM_OF_DAY} to form {@code HOUR_OF_DAY} by multiplying
       
   272      * the {AMPM_OF_DAY} value by 12.
   223      */
   273      */
   224     HOUR_OF_AMPM("HourOfAmPm", HOURS, HALF_DAYS, ValueRange.of(0, 11)),
   274     HOUR_OF_AMPM("HourOfAmPm", HOURS, HALF_DAYS, ValueRange.of(0, 11)),
   225     /**
   275     /**
   226      * The clock-hour-of-am-pm.
   276      * The clock-hour-of-am-pm.
   227      * <p>
   277      * <p>
   228      * This counts the hour within the AM/PM, from 1 to 12.
   278      * This counts the hour within the AM/PM, from 1 to 12.
   229      * This is the hour that would be observed on a standard 12-hour analog wall clock.
   279      * This is the hour that would be observed on a standard 12-hour analog wall clock.
   230      * This field has the same meaning for all calendar systems.
   280      * This field has the same meaning for all calendar systems.
       
   281      * <p>
       
   282      * When parsing this field it behaves equivalent to the following:
       
   283      * The value is validated from 1 to 12 in strict mode and from
       
   284      * 0 to 12 in smart mode. In lenient mode the value is not validated.
       
   285      * The field is converted to an {@code HOUR_OF_AMPM} with the same value,
       
   286      * unless the value is 12, in which case it is converted to 0.
   231      */
   287      */
   232     CLOCK_HOUR_OF_AMPM("ClockHourOfAmPm", HOURS, HALF_DAYS, ValueRange.of(1, 12)),
   288     CLOCK_HOUR_OF_AMPM("ClockHourOfAmPm", HOURS, HALF_DAYS, ValueRange.of(1, 12)),
   233     /**
   289     /**
   234      * The hour-of-day.
   290      * The hour-of-day.
   235      * <p>
   291      * <p>
   236      * This counts the hour within the day, from 0 to 23.
   292      * This counts the hour within the day, from 0 to 23.
   237      * This is the hour that would be observed on a standard 24-hour digital clock.
   293      * This is the hour that would be observed on a standard 24-hour digital clock.
   238      * This field has the same meaning for all calendar systems.
   294      * This field has the same meaning for all calendar systems.
       
   295      * <p>
       
   296      * When parsing this field it behaves equivalent to the following:
       
   297      * The value is validated in strict and smart mode but not in lenient mode.
       
   298      * The field is combined with {@code MINUTE_OF_HOUR}, {@code SECOND_OF_MINUTE} and
       
   299      * {@code NANO_OF_SECOND} to produce a {@code LocalTime}.
       
   300      * In lenient mode, any excess days are added to the parsed date, or
       
   301      * made available via {@link java.time.format.DateTimeFormatter#parsedExcessDays()}.
   239      */
   302      */
   240     HOUR_OF_DAY("HourOfDay", HOURS, DAYS, ValueRange.of(0, 23), "hour"),
   303     HOUR_OF_DAY("HourOfDay", HOURS, DAYS, ValueRange.of(0, 23), "hour"),
   241     /**
   304     /**
   242      * The clock-hour-of-day.
   305      * The clock-hour-of-day.
   243      * <p>
   306      * <p>
   244      * This counts the hour within the AM/PM, from 1 to 24.
   307      * This counts the hour within the AM/PM, from 1 to 24.
   245      * This is the hour that would be observed on a 24-hour analog wall clock.
   308      * This is the hour that would be observed on a 24-hour analog wall clock.
   246      * This field has the same meaning for all calendar systems.
   309      * This field has the same meaning for all calendar systems.
       
   310      * <p>
       
   311      * When parsing this field it behaves equivalent to the following:
       
   312      * The value is validated from 1 to 24 in strict mode and from
       
   313      * 0 to 24 in smart mode. In lenient mode the value is not validated.
       
   314      * The field is converted to an {@code HOUR_OF_DAY} with the same value,
       
   315      * unless the value is 24, in which case it is converted to 0.
   247      */
   316      */
   248     CLOCK_HOUR_OF_DAY("ClockHourOfDay", HOURS, DAYS, ValueRange.of(1, 24)),
   317     CLOCK_HOUR_OF_DAY("ClockHourOfDay", HOURS, DAYS, ValueRange.of(1, 24)),
   249     /**
   318     /**
   250      * The am-pm-of-day.
   319      * The am-pm-of-day.
   251      * <p>
   320      * <p>
   252      * This counts the AM/PM within the day, from 0 (AM) to 1 (PM).
   321      * This counts the AM/PM within the day, from 0 (AM) to 1 (PM).
   253      * This field has the same meaning for all calendar systems.
   322      * This field has the same meaning for all calendar systems.
       
   323      * <p>
       
   324      * When parsing this field it behaves equivalent to the following:
       
   325      * The value is validated from 0 to 1 in strict and smart mode.
       
   326      * In lenient mode the value is not validated. It is combined with
       
   327      * {@code HOUR_OF_AMPM} to form {@code HOUR_OF_DAY} by multiplying
       
   328      * the {AMPM_OF_DAY} value by 12.
   254      */
   329      */
   255     AMPM_OF_DAY("AmPmOfDay", HALF_DAYS, DAYS, ValueRange.of(0, 1), "dayperiod"),
   330     AMPM_OF_DAY("AmPmOfDay", HALF_DAYS, DAYS, ValueRange.of(0, 1), "dayperiod"),
   256     /**
   331     /**
   257      * The day-of-week, such as Tuesday.
   332      * The day-of-week, such as Tuesday.
   258      * <p>
   333      * <p>