File tree Expand file tree Collapse file tree 1 file changed +19
-15
lines changed Expand file tree Collapse file tree 1 file changed +19
-15
lines changed Original file line number Diff line number Diff line change @@ -130,22 +130,26 @@ final class Duration private (seconds: Long, nanos: Int)
130
130
new Duration (newSeconds, newNanos)
131
131
}
132
132
133
- def dividedBy (divisor : Long ): Duration = {
134
- val secondsQuot = normalizedSeconds / divisor
135
- val secondsRem = normalizedSeconds % divisor
136
- val nanos = {
137
- try {
138
- val total = Math .addExact(
139
- Math .multiplyExact(secondsRem, NANOS_IN_SECOND ),
140
- normalizedNanos)
141
- total / divisor
142
- } catch {
143
- case _ : ArithmeticException =>
144
- val total = BigInt (secondsRem) * NANOS_IN_SECOND + normalizedNanos
145
- (total / divisor).toLong
133
+ def dividedBy (divisor : Long ): Duration = divisor match {
134
+ case 1 => this
135
+ case - 1 => negated
136
+
137
+ case _ =>
138
+ val secondsQuot = normalizedSeconds / divisor
139
+ val secondsRem = normalizedSeconds % divisor
140
+ val nanos = {
141
+ try {
142
+ val total = Math .addExact(
143
+ Math .multiplyExact(secondsRem, NANOS_IN_SECOND ),
144
+ normalizedNanos)
145
+ total / divisor
146
+ } catch {
147
+ case _ : ArithmeticException =>
148
+ val total = BigInt (secondsRem) * NANOS_IN_SECOND + normalizedNanos
149
+ (total / divisor).toLong
150
+ }
146
151
}
147
- }
148
- Duration .ofSeconds(secondsQuot).plusNanos(nanos)
152
+ Duration .ofSeconds(secondsQuot).plusNanos(nanos)
149
153
}
150
154
151
155
def negated (): Duration = multipliedBy(- 1 )
You can’t perform that action at this time.
0 commit comments