src/java.base/share/classes/java/time/Instant.java
changeset 50473 bef0ed237504
parent 49433 b6671a111395
child 52078 4a63197816ce
equal deleted inserted replaced
50472:ee1a0ddb2590 50473:bef0ed237504
   309      * epoch of 1970-01-01T00:00:00Z and nanosecond fraction of second.
   309      * epoch of 1970-01-01T00:00:00Z and nanosecond fraction of second.
   310      * <p>
   310      * <p>
   311      * This method allows an arbitrary number of nanoseconds to be passed in.
   311      * This method allows an arbitrary number of nanoseconds to be passed in.
   312      * The factory will alter the values of the second and nanosecond in order
   312      * The factory will alter the values of the second and nanosecond in order
   313      * to ensure that the stored nanosecond is in the range 0 to 999,999,999.
   313      * to ensure that the stored nanosecond is in the range 0 to 999,999,999.
   314      * For example, the following will result in the exactly the same instant:
   314      * For example, the following will result in exactly the same instant:
   315      * <pre>
   315      * <pre>
   316      *  Instant.ofEpochSecond(3, 1);
   316      *  Instant.ofEpochSecond(3, 1);
   317      *  Instant.ofEpochSecond(4, -999_999_999);
   317      *  Instant.ofEpochSecond(4, -999_999_999);
   318      *  Instant.ofEpochSecond(2, 1000_000_001);
   318      *  Instant.ofEpochSecond(2, 1000_000_001);
   319      * </pre>
   319      * </pre>
   755         long dur = unitDur.toNanos();
   755         long dur = unitDur.toNanos();
   756         if ((LocalTime.NANOS_PER_DAY % dur) != 0) {
   756         if ((LocalTime.NANOS_PER_DAY % dur) != 0) {
   757             throw new UnsupportedTemporalTypeException("Unit must divide into a standard day without remainder");
   757             throw new UnsupportedTemporalTypeException("Unit must divide into a standard day without remainder");
   758         }
   758         }
   759         long nod = (seconds % LocalTime.SECONDS_PER_DAY) * LocalTime.NANOS_PER_SECOND + nanos;
   759         long nod = (seconds % LocalTime.SECONDS_PER_DAY) * LocalTime.NANOS_PER_SECOND + nanos;
   760         long result = Math.floorDiv(nod, dur) * dur ;
   760         long result = Math.floorDiv(nod, dur) * dur;
   761         return plusNanos(result - nod);
   761         return plusNanos(result - nod);
   762     }
   762     }
   763 
   763 
   764     //-----------------------------------------------------------------------
   764     //-----------------------------------------------------------------------
   765     /**
   765     /**