@@ -42,6 +42,7 @@ import java.util.regex.Pattern
42
42
import org .threeten .bp .LocalTime .SECONDS_PER_DAY
43
43
import org .threeten .bp .LocalTime .SECONDS_PER_HOUR
44
44
import org .threeten .bp .LocalTime .SECONDS_PER_MINUTE
45
+ import org .threeten .bp .LocalTime .HOURS_PER_DAY
45
46
import org .threeten .bp .format .DateTimeParseException
46
47
import org .threeten .bp .temporal .ChronoField .NANO_OF_SECOND
47
48
import org .threeten .bp .temporal .ChronoUnit
@@ -925,7 +926,7 @@ final class Duration private (private val seconds: Long, private val nanos: Int)
925
926
def multipliedBy (multiplicand : Long ): Duration =
926
927
if (multiplicand == 0 ) Duration .ZERO
927
928
else if (multiplicand == 1 ) this
928
- else Duration .create(toSeconds .multiply(BigDecimal .valueOf(multiplicand)))
929
+ else Duration .create(toSecondsBD .multiply(BigDecimal .valueOf(multiplicand)))
929
930
930
931
/**
931
932
* Returns a copy of this duration divided by the specified value.
@@ -944,7 +945,7 @@ final class Duration private (private val seconds: Long, private val nanos: Int)
944
945
def dividedBy (divisor : Long ): Duration =
945
946
if (divisor == 0 ) throw new ArithmeticException (" Cannot divide by zero" )
946
947
else if (divisor == 1 ) this
947
- else Duration .create(toSeconds .divide(BigDecimal .valueOf(divisor), RoundingMode .DOWN ))
948
+ else Duration .create(toSecondsBD .divide(BigDecimal .valueOf(divisor), RoundingMode .DOWN ))
948
949
949
950
/**
950
951
* Converts this duration to the total length in seconds and fractional nanoseconds expressed as a
@@ -953,9 +954,23 @@ final class Duration private (private val seconds: Long, private val nanos: Int)
953
954
* @return
954
955
* the total length of the duration in seconds, with a scale of 9, not null
955
956
*/
956
- private def toSeconds : BigDecimal =
957
+ private def toSecondsBD : BigDecimal =
957
958
BigDecimal .valueOf(seconds).add(BigDecimal .valueOf(nanos.toLong, 9 ))
958
959
960
+ /**
961
+ * Gets the number of seconds in this duration.
962
+ *
963
+ * This returns the total number of whole seconds in the duration.
964
+ *
965
+ * This instance is immutable and unaffected by this method call.
966
+ *
967
+ * @return
968
+ * the whole seconds part of the length of the duration, positive or negative
969
+ *
970
+ * @since 9
971
+ */
972
+ def toSeconds : Long = seconds
973
+
959
974
/**
960
975
* Returns a copy of this duration with the length negated.
961
976
*
@@ -1065,6 +1080,20 @@ final class Duration private (private val seconds: Long, private val nanos: Int)
1065
1080
*/
1066
1081
def toDays : Long = seconds / SECONDS_PER_DAY
1067
1082
1083
+ /**
1084
+ * Extracts the number of days in the duration.
1085
+ *
1086
+ * This returns the total number of days in the duration by dividing the number of seconds by
1087
+ * 86400. This is based on the standard definition of a day as 24 hours.
1088
+ *
1089
+ * This instance is immutable and unaffected by this method call.
1090
+ *
1091
+ * @return
1092
+ * the number of days in the duration, may be negative
1093
+ * @since 9
1094
+ */
1095
+ def toDaysPart : Long = seconds / SECONDS_PER_DAY
1096
+
1068
1097
/**
1069
1098
* Gets the number of hours in this duration.
1070
1099
*
@@ -1078,6 +1107,20 @@ final class Duration private (private val seconds: Long, private val nanos: Int)
1078
1107
*/
1079
1108
def toHours : Long = seconds / SECONDS_PER_HOUR
1080
1109
1110
+ /**
1111
+ * Extracts the number of hours part in the duration.
1112
+ *
1113
+ * This returns the number of remaining hours when dividing toHours() by hours in a day. This is
1114
+ * based on the standard definition of a day as 24 hours.
1115
+ *
1116
+ * This instance is immutable and unaffected by this method call.
1117
+ *
1118
+ * @return
1119
+ * the number of hours part in the duration, may be negative
1120
+ * @since 9
1121
+ */
1122
+ def toHoursPart : Int = (toHours / HOURS_PER_DAY ).toInt
1123
+
1081
1124
/**
1082
1125
* Gets the number of minutes in this duration.
1083
1126
*
0 commit comments