Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add max possible nano quantity to max possible seconds quantity in du…
…ration test
  • Loading branch information
diegomarquezp committed Aug 15, 2024
commit 86d58553fe3f74a07b605da70ea1bd8416e8394e
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@

public class TimeConversionUtilsTest {

// 0.999999999 seconds (1 second - 1 nano) - we need to subtract the nano or the Duration would
// overflow otherwise
final long MAX_DURATION_NANOS = 1 * 1000 * 1000 * 1000 - 1;

// Arbitrary durations/instants to confirm conversion works as expected
final org.threeten.bp.Duration ttDuration = org.threeten.bp.Duration.ofMillis(123);
final org.threeten.bp.Instant ttInstant = org.threeten.bp.Instant.ofEpochMilli(123);
final java.time.Duration jtDuration = java.time.Duration.ofMillis(345);
Expand Down Expand Up @@ -93,7 +98,8 @@ void testToThreeteenDuration_bigInput_doesNotOverflow() {
// we use the max long value for the seconds part and an arbitrary int for the nanos part, so we
// can confirm
// that both components are preserved
java.time.Duration jtDuration = java.time.Duration.ofSeconds(Long.MAX_VALUE, 123);
java.time.Duration jtDuration =
java.time.Duration.ofSeconds(Long.MAX_VALUE, MAX_DURATION_NANOS);
org.threeten.bp.Duration ttDuration = TimeConversionUtils.toThreetenDuration(jtDuration);
assertEquals(jtDuration.getSeconds(), ttDuration.getSeconds());
assertEquals(jtDuration.getNano(), ttDuration.getNano());
Expand All @@ -104,7 +110,8 @@ void testToJavaTimeDuration_bigInput_doesNotOverflow() {
// we use the max long value for the seconds part and an arbitrary int for the nanos part, so we
// can confirm
// that both components are preserved
org.threeten.bp.Duration ttDuration = org.threeten.bp.Duration.ofSeconds(Long.MAX_VALUE, 123);
org.threeten.bp.Duration ttDuration =
org.threeten.bp.Duration.ofSeconds(Long.MAX_VALUE, MAX_DURATION_NANOS);
java.time.Duration jtDuration = TimeConversionUtils.toJavaTimeDuration(ttDuration);
assertEquals(jtDuration.getSeconds(), ttDuration.getSeconds());
assertEquals(jtDuration.getNano(), ttDuration.getNano());
Expand Down