@@ -35,7 +35,7 @@ class InstantTest {
3535 fun instantArithmetic () {
3636 val instant = Clock .System .now().toEpochMilliseconds().let { Instant .fromEpochMilliseconds(it) } // round to millis
3737 val diffMillis = Random .nextLong(1000 , 1_000_000_000 )
38- val diff = diffMillis .milliseconds
38+ val diff = Duration .milliseconds(diffMillis)
3939
4040 val nextInstant = (instant.toEpochMilliseconds() + diffMillis).let { Instant .fromEpochMilliseconds(it) }
4141
@@ -180,7 +180,7 @@ class InstantTest {
180180 checkComponents(instant5.toLocalDateTime(zone), 2019 , 10 , 28 , 3 , 59 )
181181 assertEquals(period, instant1.periodUntil(instant5, zone))
182182 assertEquals(period, instant5.minus(instant1, zone))
183- assertEquals(26 .hours, instant5.minus(instant1))
183+ assertEquals(Duration .hours( 26 ) , instant5.minus(instant1))
184184 assertEquals(instant1.plus(DateTimeUnit .HOUR ), instant5.minus(period, zone))
185185
186186 val instant6 = instant1.plus(23 , DateTimeUnit .HOUR , zone)
@@ -237,15 +237,15 @@ class InstantTest {
237237 checkComponents(ldt1, 2019 , 10 , 27 , 2 , 59 )
238238 assertEquals(instant1, ldt1.toInstant(offset1))
239239
240- val instant2 = instant1 + 1 .hours
240+ val instant2 = instant1 + Duration .hours( 1 )
241241 val ldt2 = instant2.toLocalDateTime(zone)
242242 val offset2 = instant2.offsetIn(zone)
243243 assertEquals(ldt1, ldt2)
244244 assertEquals(instant2, ldt2.toInstant(offset2))
245245 assertNotEquals(offset1, offset2)
246- assertEquals(offset1.totalSeconds.seconds, offset2.totalSeconds.seconds + 1 .hours)
246+ assertEquals(Duration .seconds( offset1.totalSeconds), Duration .seconds( offset2.totalSeconds) + Duration .hours( 1 ) )
247247
248- val instant3 = instant2 - 2 .hours
248+ val instant3 = instant2 - Duration .hours( 2 )
249249 val offset3 = instant3.offsetIn(zone)
250250 assertEquals(offset1, offset3)
251251 }
@@ -414,10 +414,10 @@ class InstantTest {
414414 assertTrue(Instant .DISTANT_FUTURE .isDistantFuture)
415415 assertFalse(Instant .DISTANT_PAST .isDistantFuture)
416416 assertFalse(Instant .DISTANT_FUTURE .isDistantPast)
417- assertFalse((Instant .DISTANT_PAST + 1 .nanoseconds).isDistantPast)
418- assertFalse((Instant .DISTANT_FUTURE - 1 .nanoseconds).isDistantFuture)
419- assertTrue((Instant .DISTANT_PAST - 1 .nanoseconds).isDistantPast)
420- assertTrue((Instant .DISTANT_FUTURE + 1 .nanoseconds).isDistantFuture)
417+ assertFalse((Instant .DISTANT_PAST + Duration .nanoseconds( 1 ) ).isDistantPast)
418+ assertFalse((Instant .DISTANT_FUTURE - Duration .nanoseconds( 1 ) ).isDistantFuture)
419+ assertTrue((Instant .DISTANT_PAST - Duration .nanoseconds( 1 ) ).isDistantPast)
420+ assertTrue((Instant .DISTANT_FUTURE + Duration .nanoseconds( 1 ) ).isDistantFuture)
421421 assertTrue(Instant .MAX .isDistantFuture)
422422 assertFalse(Instant .MAX .isDistantPast)
423423 assertTrue(Instant .MIN .isDistantPast)
@@ -435,8 +435,8 @@ class InstantRangeTest {
435435 private val largePositiveLongs = listOf (Long .MAX_VALUE , Long .MAX_VALUE - 1 , Long .MAX_VALUE - 50 )
436436 private val largeNegativeLongs = listOf (Long .MIN_VALUE , Long .MIN_VALUE + 1 , Long .MIN_VALUE + 50 )
437437
438- private val largePositiveInstants = listOf (Instant .MAX , Instant .MAX - 1 .seconds, Instant .MAX - 50 .seconds)
439- private val largeNegativeInstants = listOf (Instant .MIN , Instant .MIN + 1 .seconds, Instant .MIN + 50 .seconds)
438+ private val largePositiveInstants = listOf (Instant .MAX , Instant .MAX - Duration .seconds( 1 ) , Instant .MAX - Duration .seconds( 50 ) )
439+ private val largeNegativeInstants = listOf (Instant .MIN , Instant .MIN + Duration .seconds( 1 ) , Instant .MIN + Duration .seconds( 50 ) )
440440
441441 private val smallInstants = listOf (
442442 Instant .fromEpochMilliseconds(0 ),
@@ -494,7 +494,7 @@ class InstantRangeTest {
494494
495495 @Test
496496 fun durationArithmeticClamping () {
497- val longDurations = listOf (Duration .INFINITE , Double . MAX_VALUE .nanoseconds, Long . MAX_VALUE .seconds )
497+ val longDurations = listOf (Duration .INFINITE )
498498
499499 for (duration in longDurations) {
500500 for (instant in smallInstants + largeNegativeInstants + largePositiveInstants) {
@@ -504,8 +504,8 @@ class InstantRangeTest {
504504 assertEquals(Instant .MIN , instant - duration)
505505 }
506506 }
507- assertEquals(Instant .MAX , (Instant .MAX - 4 .seconds) + 5 .seconds)
508- assertEquals(Instant .MIN , (Instant .MIN + 10 .seconds) - 12 .seconds)
507+ assertEquals(Instant .MAX , (Instant .MAX - Duration .seconds( 4 )) + Duration .seconds( 5 ) )
508+ assertEquals(Instant .MIN , (Instant .MIN + Duration .seconds( 10 )) - Duration .seconds( 12 ) )
509509 }
510510
511511 @Test
@@ -534,8 +534,8 @@ class InstantRangeTest {
534534 // Overflowing a LocalDateTime in input
535535 maxValidInstant.plus(DateTimePeriod (nanoseconds = - 1 ), UTC )
536536 minValidInstant.plus(DateTimePeriod (nanoseconds = 1 ), UTC )
537- assertArithmeticFails { (maxValidInstant + 1 .nanoseconds).plus(DateTimePeriod (nanoseconds = - 2 ), UTC ) }
538- assertArithmeticFails { (minValidInstant - 1 .nanoseconds).plus(DateTimePeriod (nanoseconds = 2 ), UTC ) }
537+ assertArithmeticFails { (maxValidInstant + Duration .nanoseconds( 1 ) ).plus(DateTimePeriod (nanoseconds = - 2 ), UTC ) }
538+ assertArithmeticFails { (minValidInstant - Duration .nanoseconds( 1 ) ).plus(DateTimePeriod (nanoseconds = 2 ), UTC ) }
539539 // Overflowing a LocalDateTime in result
540540 assertArithmeticFails { maxValidInstant.plus(DateTimePeriod (nanoseconds = 1 ), UTC ) }
541541 assertArithmeticFails { minValidInstant.plus(DateTimePeriod (nanoseconds = - 1 ), UTC ) }
@@ -557,8 +557,8 @@ class InstantRangeTest {
557557 // Overflowing a LocalDateTime in input
558558 maxValidInstant.plus(- 1 , DateTimeUnit .NANOSECOND , UTC )
559559 minValidInstant.plus(1 , DateTimeUnit .NANOSECOND , UTC )
560- assertArithmeticFails { (maxValidInstant + 1 .nanoseconds).plus(- 2 , DateTimeUnit .NANOSECOND , UTC ) }
561- assertArithmeticFails { (minValidInstant - 1 .nanoseconds).plus(2 , DateTimeUnit .NANOSECOND , UTC ) }
560+ assertArithmeticFails { (maxValidInstant + Duration .nanoseconds( 1 ) ).plus(- 2 , DateTimeUnit .NANOSECOND , UTC ) }
561+ assertArithmeticFails { (minValidInstant - Duration .nanoseconds( 1 ) ).plus(2 , DateTimeUnit .NANOSECOND , UTC ) }
562562 // Overflowing a LocalDateTime in result
563563 assertArithmeticFails { maxValidInstant.plus(1 , DateTimeUnit .NANOSECOND , UTC ) }
564564 assertArithmeticFails { maxValidInstant.plus(1 , DateTimeUnit .YEAR , UTC ) }
@@ -586,8 +586,8 @@ class InstantRangeTest {
586586 fun periodUntilOutOfRange () {
587587 // Instant.periodUntil
588588 maxValidInstant.periodUntil(maxValidInstant, UTC )
589- assertArithmeticFails { (maxValidInstant + 1 .nanoseconds).periodUntil(maxValidInstant, UTC ) }
590- assertArithmeticFails { minValidInstant.periodUntil(minValidInstant - 1 .nanoseconds, UTC ) }
589+ assertArithmeticFails { (maxValidInstant + Duration .nanoseconds( 1 ) ).periodUntil(maxValidInstant, UTC ) }
590+ assertArithmeticFails { minValidInstant.periodUntil(minValidInstant - Duration .nanoseconds( 1 ) , UTC ) }
591591 }
592592
593593 @Test
@@ -603,11 +603,11 @@ class InstantRangeTest {
603603 fun unitsUntilOutOfRange () {
604604 // Instant.until
605605 // Overflowing a LocalDateTime in input
606- assertArithmeticFails { (maxValidInstant + 1 .nanoseconds).until(maxValidInstant, DateTimeUnit .NANOSECOND , UTC ) }
607- assertArithmeticFails { maxValidInstant.until(maxValidInstant + 1 .nanoseconds, DateTimeUnit .NANOSECOND , UTC ) }
606+ assertArithmeticFails { (maxValidInstant + Duration .nanoseconds( 1 ) ).until(maxValidInstant, DateTimeUnit .NANOSECOND , UTC ) }
607+ assertArithmeticFails { maxValidInstant.until(maxValidInstant + Duration .nanoseconds( 1 ) , DateTimeUnit .NANOSECOND , UTC ) }
608608 // Overloads without a TimeZone should not fail on overflowing a LocalDateTime
609- (maxValidInstant + 1 .nanoseconds).until(maxValidInstant, DateTimeUnit .NANOSECOND )
610- maxValidInstant.until(maxValidInstant + 1 .nanoseconds, DateTimeUnit .NANOSECOND )
609+ (maxValidInstant + Duration .nanoseconds( 1 ) ).until(maxValidInstant, DateTimeUnit .NANOSECOND )
610+ maxValidInstant.until(maxValidInstant + Duration .nanoseconds( 1 ) , DateTimeUnit .NANOSECOND )
611611 }
612612}
613613
0 commit comments