< prev index next >
src/java.base/share/classes/java/time/Duration.java
Print this page
8204444: java.time cleanup
Reviewed-by: scolebourne, rriggs
@@ -229,11 +229,11 @@
* adjustment in nanoseconds.
* <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 duration:
+ * For example, the following will result in exactly the same duration:
* <pre>
* Duration.ofSeconds(3, 1);
* Duration.ofSeconds(4, -999_999_999);
* Duration.ofSeconds(2, 1000_000_001);
* </pre>
@@ -1355,16 +1355,18 @@
* Returns a copy of this {@code Duration} truncated to the specified unit.
* <p>
* Truncating the duration returns a copy of the original with conceptual fields
* smaller than the specified unit set to zero.
* For example, truncating with the {@link ChronoUnit#MINUTES MINUTES} unit will
- * round down to the nearest minute, setting the seconds and nanoseconds to zero.
+ * round down towards zero to the nearest minute, setting the seconds and
+ * nanoseconds to zero.
* <p>
* The unit must have a {@linkplain TemporalUnit#getDuration() duration}
* that divides into the length of a standard day without remainder.
- * This includes all supplied time units on {@link ChronoUnit} and
- * {@link ChronoUnit#DAYS DAYS}. Other ChronoUnits throw an exception.
+ * This includes all
+ * {@linkplain ChronoUnit#isTimeBased() time-based units on {@code ChronoUnit}}
+ * and {@link ChronoUnit#DAYS DAYS}. Other ChronoUnits throw an exception.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param unit the unit to truncate to, not null
* @return a {@code Duration} based on this duration with the time truncated, not null
@@ -1386,11 +1388,11 @@
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 = (nod / dur) * dur ;
+ long result = (nod / dur) * dur;
return plusNanos(result - nod);
}
//-----------------------------------------------------------------------
/**
< prev index next >