< prev index next >

src/java.base/share/classes/java/time/Instant.java

Print this page
8204444: java.time cleanup
Reviewed-by: scolebourne, rriggs

*** 309,319 **** * epoch of 1970-01-01T00:00:00Z and nanosecond fraction of second. * <p> * This method allows an arbitrary number of nanoseconds to be passed in. * The factory will alter the values of the second and nanosecond in order * to ensure that the stored nanosecond is in the range 0 to 999,999,999. ! * For example, the following will result in the exactly the same instant: * <pre> * Instant.ofEpochSecond(3, 1); * Instant.ofEpochSecond(4, -999_999_999); * Instant.ofEpochSecond(2, 1000_000_001); * </pre> --- 309,319 ---- * epoch of 1970-01-01T00:00:00Z and nanosecond fraction of second. * <p> * This method allows an arbitrary number of nanoseconds to be passed in. * The factory will alter the values of the second and nanosecond in order * to ensure that the stored nanosecond is in the range 0 to 999,999,999. ! * For example, the following will result in exactly the same instant: * <pre> * Instant.ofEpochSecond(3, 1); * Instant.ofEpochSecond(4, -999_999_999); * Instant.ofEpochSecond(2, 1000_000_001); * </pre>
*** 755,765 **** long dur = unitDur.toNanos(); if ((LocalTime.NANOS_PER_DAY % dur) != 0) { throw new UnsupportedTemporalTypeException("Unit must divide into a standard day without remainder"); } long nod = (seconds % LocalTime.SECONDS_PER_DAY) * LocalTime.NANOS_PER_SECOND + nanos; ! long result = Math.floorDiv(nod, dur) * dur ; return plusNanos(result - nod); } //----------------------------------------------------------------------- /** --- 755,765 ---- long dur = unitDur.toNanos(); if ((LocalTime.NANOS_PER_DAY % dur) != 0) { throw new UnsupportedTemporalTypeException("Unit must divide into a standard day without remainder"); } long nod = (seconds % LocalTime.SECONDS_PER_DAY) * LocalTime.NANOS_PER_SECOND + nanos; ! long result = Math.floorDiv(nod, dur) * dur; return plusNanos(result - nod); } //----------------------------------------------------------------------- /**
< prev index next >