mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-12-01 15:37:14 +00:00
#1272 - ENH: Add built in support for Joda Period
This commit is contained in:
1 parent
7d0ed261b5
commit
265bda8cf2
5 files changed
+105
-1
No files matched your search
@@ -0,0 +1,43 @@
|
||||
package io.ebeaninternal.server.type;
|
||||
|
||||
import org.joda.time.Period;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class ScalarTypeJodaPeriodTest {
|
||||
|
||||
private ScalarTypeJodaPeriod scalarType = new ScalarTypeJodaPeriod();
|
||||
|
||||
@Test
|
||||
public void getLength() {
|
||||
assertThat(scalarType.getLength()).isEqualTo(50);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void formatAndParse() {
|
||||
|
||||
Period original = Period.years(1).plusMonths(2).plusDays(4)
|
||||
.plusHours(12).plusMinutes(19).plusSeconds(20);
|
||||
|
||||
String value = scalarType.formatValue(original);
|
||||
assertThat(value).isEqualTo("P1Y2M4DT12H19M20S");
|
||||
|
||||
Period period = scalarType.parse(value);
|
||||
assertThat(period).isEqualTo(original);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void convertFromDbString() {
|
||||
|
||||
Period original = Period.years(1).plusMonths(2).plusDays(4)
|
||||
.plusHours(23).plusMinutes(19).plusSeconds(20).plusMillis(987);
|
||||
|
||||
String stringVal = scalarType.convertToDbString(original);
|
||||
Period period = scalarType.convertFromDbString(stringVal);
|
||||
|
||||
assertThat(period).isEqualTo(original);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user