mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1272 - ENH: Add built in support for Joda Period
This commit is contained in:
@@ -875,6 +875,7 @@ public final class DefaultTypeManager implements TypeManager {
|
||||
typeMap.put(DateTime.class, new ScalarTypeJodaDateTime(mode));
|
||||
typeMap.put(LocalDate.class, new ScalarTypeJodaLocalDate());
|
||||
typeMap.put(org.joda.time.DateMidnight.class, new ScalarTypeJodaDateMidnight());
|
||||
typeMap.put(org.joda.time.Period.class, new ScalarTypeJodaPeriod());
|
||||
|
||||
String jodaLocalTimeMode = config.getJodaLocalTimeMode();
|
||||
if ("normal".equalsIgnoreCase(jodaLocalTimeMode)) {
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package io.ebeaninternal.server.type;
|
||||
|
||||
import org.joda.time.Period;
|
||||
|
||||
/**
|
||||
* ScalarType for Joda Period stored as DB VARCHAR
|
||||
*/
|
||||
public class ScalarTypeJodaPeriod extends ScalarTypeBaseVarchar<Period> {
|
||||
|
||||
public ScalarTypeJodaPeriod() {
|
||||
super(Period.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return 50;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatValue(Period v) {
|
||||
return v.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Period parse(String value) {
|
||||
return Period.parse(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Period convertFromDbString(String dbValue) {
|
||||
return Period.parse(dbValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToDbString(Period beanValue) {
|
||||
return beanValue.toString();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user