mirror of
https://github.com/dalbodeule/snap-admin.git
synced 2025-12-15 04:41:58 +09:00
Enabled OffsetDateTime support
This commit is contained in:
@@ -123,29 +123,29 @@ public enum DbFieldType {
|
||||
return List.of(CompareOperator.GT, CompareOperator.EQ, CompareOperator.LT);
|
||||
}
|
||||
},
|
||||
// OFFSET_DATE_TIME {
|
||||
// @Override
|
||||
// public String getFragmentName(FragmentContext c) {
|
||||
// return "text";
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Object parseValue(Object value) {
|
||||
// if (value == null) return null;
|
||||
// return OffsetDateTime.parse(value.toString());
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Class<?> getJavaClass() {
|
||||
// return OffsetDateTime.class;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List<CompareOperator> getCompareOperators() {
|
||||
// return List.of(CompareOperator.AFTER, CompareOperator.STRING_EQ, CompareOperator.BEFORE);
|
||||
// }
|
||||
//
|
||||
// },
|
||||
OFFSET_DATE_TIME {
|
||||
@Override
|
||||
public String getFragmentName(FragmentContext c) {
|
||||
return "datetime";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object parseValue(Object value) {
|
||||
if (value == null) return null;
|
||||
return OffsetDateTime.parse(value.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getJavaClass() {
|
||||
return OffsetDateTime.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CompareOperator> getCompareOperators() {
|
||||
return List.of(CompareOperator.AFTER, CompareOperator.STRING_EQ, CompareOperator.BEFORE);
|
||||
}
|
||||
|
||||
},
|
||||
LOCAL_DATE {
|
||||
@Override
|
||||
public String getFragmentName(FragmentContext c) {
|
||||
@@ -450,8 +450,8 @@ public enum DbFieldType {
|
||||
return BIG_DECIMAL;
|
||||
} else if (klass == byte[].class) {
|
||||
return BYTE_ARRAY;
|
||||
// } else if (klass == OffsetDateTime.class) {
|
||||
// return OFFSET_DATE_TIME;
|
||||
} else if (klass == OffsetDateTime.class) {
|
||||
return OFFSET_DATE_TIME;
|
||||
} else {
|
||||
throw new DbAdminException("Unsupported field type: " + klass);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
package tech.ailef.dbadmin.external.dbmapping;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
@@ -38,6 +40,17 @@ public class DbFieldValue {
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
/*
|
||||
* Special handling of OffsetDateTime to be compatbile
|
||||
* with the HTML datetime-local input field: we "cast"
|
||||
* it to a LocalDateTime so the toString() method will
|
||||
* not produce the ending "Z" which prevents the datepicker
|
||||
* to be autofilled on edit pages.
|
||||
*/
|
||||
if (value instanceof OffsetDateTime) {
|
||||
return LocalDateTime.from((OffsetDateTime)value);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user