@@ -137,6 +137,29 @@ class InstantTest {
137
137
assertEquals(0 , instant6.minus(instant1, DateTimeUnit .DAY , zone))
138
138
}
139
139
140
+ @OptIn(ExperimentalTime ::class )
141
+ @Test
142
+ fun unitMultiplesUntil () {
143
+ val unit1000days = DateTimeUnit .DAY * 1000
144
+ val unit4years = DateTimeUnit .YEAR * 4 // longer than 1000-DAY
145
+
146
+ val zone = TimeZone .UTC
147
+ val min = LocalDateTime .MIN .toInstant(zone)
148
+ val max = LocalDateTime .MAX .toInstant(zone)
149
+ val diffDays = min.until(max, unit1000days, zone)
150
+ val diffYears = min.until(max, unit4years, zone)
151
+ assertTrue(diffDays in 0 .. Int .MAX_VALUE , " difference in $unit1000days should fit in Int, was $diffDays " )
152
+ assertTrue(diffDays > diffYears, " difference in $unit1000days unit must be more than in $unit4years unit, was $diffDays $diffYears " )
153
+
154
+ val unit500ns = DateTimeUnit .NANOSECOND * 500
155
+ val start = Instant .parse(" 1700-01-01T00:00:00Z" )
156
+ val end = start.plus(300 , DateTimeUnit .YEAR , zone)
157
+ val diffNs = start.until(end, unit500ns, zone)
158
+ val diffUs = start.until(end, DateTimeUnit .MICROSECOND , zone)
159
+ // TODO: avoid clamping/overflowing in intermediate results
160
+ // assertEquals(diffUs * 2, diffNs)
161
+ }
162
+
140
163
@OptIn(ExperimentalTime ::class )
141
164
@Test
142
165
fun instantOffset () {
0 commit comments