mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Refactor move ScalarTypeBaseDateTime to ebean-core-type module
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
package io.ebeaninternal.server.type;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class DecimalUtilsTest {
|
||||
|
||||
@Test
|
||||
void testToDecimal() {
|
||||
Instant now = Instant.now();
|
||||
Timestamp sourceTimestamp = Timestamp.from(now);
|
||||
|
||||
BigDecimal decimal = DecimalUtils.toDecimal(sourceTimestamp);
|
||||
Timestamp timestamp = DecimalUtils.toTimestamp(decimal);
|
||||
|
||||
assertEquals(now, timestamp.toInstant());
|
||||
assertEquals(sourceTimestamp, timestamp);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDuration() {
|
||||
Duration duration = Duration.ofSeconds(323, 1500000);
|
||||
|
||||
BigDecimal bigDecimal = DecimalUtils.toDecimal(duration);
|
||||
Duration duration1 = DecimalUtils.toDuration(bigDecimal);
|
||||
|
||||
assertEquals(duration, duration1);
|
||||
assertEquals("PT5M23.0015S", duration1.toString());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package io.ebeaninternal.server.type;
|
||||
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class IsoJsonDateTimeParserTest {
|
||||
|
||||
private IsoJsonDateTimeParser parser = new IsoJsonDateTimeParser();
|
||||
|
||||
@Test
|
||||
public void parseFormat_when_hasMillis() {
|
||||
parseAndFormat("2016-02-28T20:39:00.123Z", "2016-02-28T20:39:00.123Z");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseFormat_when_noMillis() {
|
||||
parseAndFormat("2016-02-28T20:39:00Z", "2016-02-28T20:39:00.000Z");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseFormat_when_millis_1dp() {
|
||||
parseAndFormat("2016-02-28T20:39:00.0Z", "2016-02-28T20:39:00.000Z");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseFormat_when_millis_2dp() {
|
||||
parseAndFormat("2016-02-28T20:39:00.00Z", "2016-02-28T20:39:00.000Z");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseFormat_when_millis_3dp() {
|
||||
parseAndFormat("2016-02-28T20:39:00.000Z", "2016-02-28T20:39:00.000Z");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseFormat_when_millis_3dp_2() {
|
||||
parseAndFormat("2016-02-28T20:39:32.999000Z", "2016-02-28T20:39:32.999Z");
|
||||
}
|
||||
|
||||
private void parseAndFormat(String input, String expected) {
|
||||
Instant timestamp = parser.parseIso(input);
|
||||
String format = parser.formatIso(timestamp);
|
||||
assertThat(format).isEqualTo(expected);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.ebeaninternal.server.type;
|
||||
|
||||
import io.ebean.config.JsonConfig;
|
||||
import io.ebean.core.type.IsoJsonDateTimeParser;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.Types;
|
||||
@@ -17,7 +18,7 @@ public class ScalarTypeCalendarTest {
|
||||
|
||||
Calendar instance = Calendar.getInstance();
|
||||
String asUtc = type.toJsonISO8601(instance);
|
||||
Calendar calendar = type.fromJsonISO8601(asUtc);
|
||||
Calendar calendar = type.convertFromInstant(IsoJsonDateTimeParser.parseIso(asUtc)); //type.fromJsonISO8601(asUtc);
|
||||
|
||||
assertThat(instance).isEqualTo(calendar);
|
||||
}
|
||||
|
||||
+1
@@ -1,5 +1,6 @@
|
||||
package io.ebeaninternal.server.type;
|
||||
|
||||
import io.ebean.core.type.DecimalUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
package io.ebeaninternal.server.type;
|
||||
|
||||
import io.ebean.config.JsonConfig;
|
||||
import io.ebean.core.type.IsoJsonDateTimeParser;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
@@ -122,7 +123,7 @@ public class ScalarTypeOffsetDateTimeTest {
|
||||
OffsetDateTime now = OffsetDateTime.now();
|
||||
String asJson = typeIso.toJsonISO8601(now);
|
||||
|
||||
OffsetDateTime value = typeIso.fromJsonISO8601(asJson);
|
||||
OffsetDateTime value = typeIso.convertFromInstant(IsoJsonDateTimeParser.parseIso(asJson)); //typeIso.fromJsonISO8601(asJson);
|
||||
assertThat(now).isEqualToIgnoringNanos(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.ebeaninternal.server.type;
|
||||
|
||||
import io.ebean.config.JsonConfig;
|
||||
import io.ebean.core.type.IsoJsonDateTimeParser;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
@@ -17,7 +18,7 @@ public class ScalarTypeTimestampTest {
|
||||
Timestamp now = new Timestamp(System.currentTimeMillis());
|
||||
String asJson = typeIso.toJsonISO8601(now);
|
||||
|
||||
Timestamp value = typeIso.fromJsonISO8601(asJson);
|
||||
Timestamp value = typeIso.convertFromInstant(IsoJsonDateTimeParser.parseIso(asJson)); //typeIso.fromJsonISO8601(asJson);
|
||||
assertThat(now).isEqualTo(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package io.ebeaninternal.server.type;
|
||||
|
||||
import io.ebean.config.JsonConfig;
|
||||
import io.ebean.core.type.IsoJsonDateTimeParser;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.Date;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -33,7 +35,8 @@ public class ScalarTypeUtilDateTest {
|
||||
Date now = new Date();
|
||||
String asJson = typeIso.toJsonISO8601(now);
|
||||
|
||||
Date value = typeIso.fromJsonISO8601(asJson);
|
||||
Instant instant = IsoJsonDateTimeParser.parseIso(asJson);
|
||||
Date value = new java.util.Date(instant.toEpochMilli()); // typeIso.fromJsonISO8601(asJson);
|
||||
assertThat(now).isEqualTo(value);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
package io.ebeaninternal.server.type;
|
||||
|
||||
import io.ebean.config.JsonConfig;
|
||||
import io.ebean.core.type.IsoJsonDateTimeParser;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
@@ -124,7 +125,7 @@ public class ScalarTypeZonedDateTimeTest {
|
||||
ZonedDateTime now = ZonedDateTime.now();
|
||||
String asJson = typeIso.toJsonISO8601(now);
|
||||
|
||||
ZonedDateTime value = typeIso.fromJsonISO8601(asJson);
|
||||
ZonedDateTime value = type.convertFromInstant(IsoJsonDateTimeParser.parseIso(asJson)); //typeIso.fromJsonISO8601(asJson);
|
||||
assertThat(now).isEqualTo(value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user