Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8330135

ChronoField.INSTANT_SECONDS's range doesn't match the range of Instant

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 23
    • core-libs
    • None
    • behavioral
    • low
    • Chances of any application relying on values that aren't within the epoch seconds range supported by java.time.Instant are low.
    • Java API
    • SE

      Summary

      The minimum and maximum values supported by java.time.temporal.ChronoField.INSTANT_SECONDS will be changed to -31557014167219200L and 31556889864403199L respectively.

      Problem

      java.time.temporal.ChronoField provides a standard set of fields that are applicable in multiple calendar systems. These fields provide field-based access to manipulate date, time or date-time. One such field is the java.time.temporal.ChronoField.INSTANT_SECONDS. The INSTANT_SECONDS represents the instant epoch seconds which is the sequential count of seconds where 1970-01-01T00:00Z (ISO) is represented as zero.The minimum and maximum values that are currently allowed for ChronoField.INSTANT_SECONDS is Long.MIN_VALUE (-9223372036854775808L) and Long.MAX_VALUE (9223372036854775807L) respectively.

      java.time.Instant is a class which represents an instantaneous point on the time-line. The Instant class supports -31557014167219200L as the minimum epoch second and 31556889864403199L as the maximum epoch second. Any attempt to construct an Instant using an epoch second value that isn't within this range will cause a java.time.DateTimeException.

      ChronoField.INSTANT_SECONDS's minimum and maximum epoch second values thus don't match the minimum and maximum epoch seconds supported by the Instant class.

      Solution

      The java.time.temporal.ChronoField.INSTANT_SECONDS's value range will be updated to -31557014167219200L and 31556889864403199L as the minimum and maximum allowed epoch seconds. This will match the epoch seconds supported by the java.time.Instant class.

      Specification

      diff --git a/src/java.base/share/classes/java/time/temporal/ChronoField.java b/src/java.base/share/classes/java/time/temporal/ChronoField.java
      --- a/src/java.base/share/classes/java/time/temporal/ChronoField.java
      +++ b/src/java.base/share/classes/java/time/temporal/ChronoField.java
      @@ -586,8 +586,11 @@ public enum ChronoField implements TemporalField {
            * <p>
            * This field is strictly defined to have the same meaning in all calendar systems.
            * This is necessary to ensure interoperation between calendars.
      +     * <p>
      +     * Range of InstantSeconds is between {@link Instant#MIN} and {@link Instant#MAX}
      +     * {@linkplain Instant#getEpochSecond() epoch second}, both inclusive.
            */
      -    INSTANT_SECONDS("InstantSeconds", SECONDS, FOREVER, ValueRange.of(Long.MIN_VALUE, Long.MAX_VALUE)),
      +    INSTANT_SECONDS("InstantSeconds", SECONDS, FOREVER, ValueRange.of(Instant.MIN.getEpochSecond(), Instant.MAX.getEpochSecond())),

            jpai Jaikiran Pai
            webbuggrp Webbug Group
            Naoto Sato
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: