DecimalUtils - remove unused methods converting between Instance and BigDecimal

This commit is contained in:
Rob Bygrave
2022-08-26 12:24:15 +12:00
parent 5667f1b118
commit 13a913428e
2 changed files with 8 additions and 25 deletions
@@ -61,16 +61,6 @@ final class DecimalUtils {
return new BigDecimal(toDecimal(secs, instant.getNanos()));
}
static Instant toInstant(BigDecimal value) {
long seconds = value.longValue();
int nanoseconds = extractNanosecondDecimal(value, seconds);
return Instant.ofEpochSecond(seconds, nanoseconds);
}
static BigDecimal toDecimal(Instant instant) {
return new BigDecimal(toDecimal(instant.getEpochSecond(), instant.getNano()));
}
static String toDecimal(long seconds, int nanoseconds) {
StringBuilder string = new StringBuilder(Integer.toString(nanoseconds));
if (string.length() < 9)
@@ -9,29 +9,22 @@ import java.time.Instant;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class DecimalUtilsTest {
class DecimalUtilsTest {
@Test
public void testToDecimal() throws Exception {
void testToDecimal() {
Instant now = Instant.now();
BigDecimal value = DecimalUtils.toDecimal(now);
Timestamp sourceTimestamp = Timestamp.from(now);
Instant instant = DecimalUtils.toInstant(value);
Timestamp timestamp = DecimalUtils.toTimestamp(value);
BigDecimal decimal = DecimalUtils.toDecimal(timestamp);
BigDecimal decimal = DecimalUtils.toDecimal(sourceTimestamp);
Timestamp timestamp = DecimalUtils.toTimestamp(decimal);
Instant instant1 = timestamp.toInstant();
assertEquals(instant, instant1);
assertEquals(value, decimal);
assertEquals(now, instant);
assertEquals(now, timestamp.toInstant());
assertEquals(sourceTimestamp, timestamp);
}
@Test
public void testDuration() throws Exception {
void testDuration() {
Duration duration = Duration.ofSeconds(323, 1500000);
BigDecimal bigDecimal = DecimalUtils.toDecimal(duration);