@@ -42,6 +42,8 @@ import java.util.regex.Pattern
4242import org .threeten .bp .LocalTime .SECONDS_PER_DAY
4343import org .threeten .bp .LocalTime .SECONDS_PER_HOUR
4444import org .threeten .bp .LocalTime .SECONDS_PER_MINUTE
45+ import org .threeten .bp .LocalTime .HOURS_PER_DAY
46+ import org .threeten .bp .LocalTime .MINUTES_PER_HOUR
4547import org .threeten .bp .format .DateTimeParseException
4648import org .threeten .bp .temporal .ChronoField .NANO_OF_SECOND
4749import org .threeten .bp .temporal .ChronoUnit
@@ -925,7 +927,7 @@ final class Duration private (private val seconds: Long, private val nanos: Int)
925927 def multipliedBy (multiplicand : Long ): Duration =
926928 if (multiplicand == 0 ) Duration .ZERO
927929 else if (multiplicand == 1 ) this
928- else Duration .create(toSeconds .multiply(BigDecimal .valueOf(multiplicand)))
930+ else Duration .create(toSecondsBD .multiply(BigDecimal .valueOf(multiplicand)))
929931
930932 /**
931933 * Returns a copy of this duration divided by the specified value.
@@ -944,7 +946,7 @@ final class Duration private (private val seconds: Long, private val nanos: Int)
944946 def dividedBy (divisor : Long ): Duration =
945947 if (divisor == 0 ) throw new ArithmeticException (" Cannot divide by zero" )
946948 else if (divisor == 1 ) this
947- else Duration .create(toSeconds .divide(BigDecimal .valueOf(divisor), RoundingMode .DOWN ))
949+ else Duration .create(toSecondsBD .divide(BigDecimal .valueOf(divisor), RoundingMode .DOWN ))
948950
949951 /**
950952 * Converts this duration to the total length in seconds and fractional nanoseconds expressed as a
@@ -953,9 +955,37 @@ final class Duration private (private val seconds: Long, private val nanos: Int)
953955 * @return
954956 * the total length of the duration in seconds, with a scale of 9, not null
955957 */
956- private def toSeconds : BigDecimal =
958+ private def toSecondsBD : BigDecimal =
957959 BigDecimal .valueOf(seconds).add(BigDecimal .valueOf(nanos.toLong, 9 ))
958960
961+ /**
962+ * Gets the number of seconds in this duration.
963+ *
964+ * This returns the total number of whole seconds in the duration.
965+ *
966+ * This instance is immutable and unaffected by this method call.
967+ *
968+ * @return
969+ * the whole seconds part of the length of the duration, positive or negative
970+ *
971+ * @since 9
972+ */
973+ def toSeconds : Long = seconds
974+
975+ /**
976+ * Extracts the number of seconds part in the duration.
977+ *
978+ * This returns the remaining seconds when dividing toSeconds() by seconds in a minute. This is
979+ * based on the standard definition of a minute as 60 seconds.
980+ *
981+ * This instance is immutable and unaffected by this method call.
982+ *
983+ * @return
984+ * the number of seconds parts in the duration, may be negative
985+ * @since 9
986+ */
987+ def toSecondsPart : Int = (toSeconds % SECONDS_PER_MINUTE ).toInt
988+
959989 /**
960990 * Returns a copy of this duration with the length negated.
961991 *
@@ -1065,6 +1095,20 @@ final class Duration private (private val seconds: Long, private val nanos: Int)
10651095 */
10661096 def toDays : Long = seconds / SECONDS_PER_DAY
10671097
1098+ /**
1099+ * Extracts the number of days in the duration.
1100+ *
1101+ * This returns the total number of days in the duration by dividing the number of seconds by
1102+ * 86400. This is based on the standard definition of a day as 24 hours.
1103+ *
1104+ * This instance is immutable and unaffected by this method call.
1105+ *
1106+ * @return
1107+ * the number of days in the duration, may be negative
1108+ * @since 9
1109+ */
1110+ def toDaysPart : Long = seconds / SECONDS_PER_DAY
1111+
10681112 /**
10691113 * Gets the number of hours in this duration.
10701114 *
@@ -1078,6 +1122,20 @@ final class Duration private (private val seconds: Long, private val nanos: Int)
10781122 */
10791123 def toHours : Long = seconds / SECONDS_PER_HOUR
10801124
1125+ /**
1126+ * Extracts the number of hours part in the duration.
1127+ *
1128+ * This returns the number of remaining hours when dividing toHours() by hours in a day. This is
1129+ * based on the standard definition of a day as 24 hours.
1130+ *
1131+ * This instance is immutable and unaffected by this method call.
1132+ *
1133+ * @return
1134+ * the number of hours part in the duration, may be negative
1135+ * @since 9
1136+ */
1137+ def toHoursPart : Int = (toHours % HOURS_PER_DAY ).toInt
1138+
10811139 /**
10821140 * Gets the number of minutes in this duration.
10831141 *
@@ -1091,6 +1149,20 @@ final class Duration private (private val seconds: Long, private val nanos: Int)
10911149 */
10921150 def toMinutes : Long = seconds / SECONDS_PER_MINUTE
10931151
1152+ /**
1153+ * Extracts the number of minutes part in the duration.
1154+ *
1155+ * This returns the number of remaining minutes when dividing toMinutes() by minutes in an hour.
1156+ * This is based on the standard definition of an hour as 60 minutes.
1157+ *
1158+ * This instance is immutable and unaffected by this method call.
1159+ *
1160+ * @return
1161+ * the number of minutes parts in the duration, may be negative
1162+ * @since 9
1163+ */
1164+ def toMinutesPart : Int = (toMinutes % MINUTES_PER_HOUR ).toInt
1165+
10941166 /**
10951167 * Converts this duration to the total length in milliseconds.
10961168 *
@@ -1111,6 +1183,22 @@ final class Duration private (private val seconds: Long, private val nanos: Int)
11111183 Math .addExact(result, nanos.toLong / Duration .NANOS_PER_MILLI )
11121184 }
11131185
1186+ /**
1187+ * Extracts the number of milliseconds part of the duration.
1188+ *
1189+ * This returns the milliseconds part by dividing the number of nanoseconds by 1,000,000. The
1190+ * length of the duration is stored using two fields - seconds and nanoseconds. The nanoseconds
1191+ * part is a value from 0 to 999,999,999 that is an adjustment to the length in seconds. The total
1192+ * duration is defined by calling getNano() and getSeconds().
1193+ *
1194+ * This instance is immutable and unaffected by this method call.
1195+ *
1196+ * @return
1197+ * the number of milliseconds part of the duration.
1198+ * @since 9
1199+ */
1200+ def toMillisPart : Int = (nanos / Duration .NANOS_PER_MILLI ).toInt
1201+
11141202 /**
11151203 * Converts this duration to the total length in nanoseconds expressed as a {@code long}.
11161204 *
@@ -1127,6 +1215,21 @@ final class Duration private (private val seconds: Long, private val nanos: Int)
11271215 Math .addExact(result, nanos.toLong)
11281216 }
11291217
1218+ /**
1219+ * Get the nanoseconds part within seconds of the duration.
1220+ *
1221+ * The length of the duration is stored using two fields - seconds and nanoseconds. The
1222+ * nanoseconds part is a value from 0 to 999,999,999 that is an adjustment to the length in
1223+ * seconds. The total duration is defined by calling getNano() and getSeconds().
1224+ *
1225+ * This instance is immutable and unaffected by this method call.
1226+ *
1227+ * @return
1228+ * the nanoseconds within the second part of the length of the duration, from 0 to 999,999,999
1229+ * @since 9
1230+ */
1231+ def toNanosPart : Int = nanos
1232+
11301233 /**
11311234 * Compares this duration to the specified {@code Duration}.
11321235 *
0 commit comments