No effective change, tidy ScalarTypeBaseDate only

This commit is contained in:
Rob Bygrave
2022-08-26 12:36:04 +12:00
parent 09e20934d7
commit 6f249c7b72
@@ -28,6 +28,11 @@ public abstract class ScalarTypeBaseDate<T> extends ScalarTypeBase<T> {
this.mode = mode;
}
/**
* Convert the value to ISO8601 format.
*/
protected abstract String toIsoFormat(T value);
/**
* Convert the target value to millis.
*/
@@ -54,32 +59,27 @@ public abstract class ScalarTypeBaseDate<T> extends ScalarTypeBase<T> {
@Override
public T read(DataReader reader) throws SQLException {
Date ts = reader.getDate();
return ts == null ? null : convertFromDate(ts);
final Date date = reader.getDate();
return date == null ? null : convertFromDate(date);
}
@Override
public String formatValue(T t) {
Date date = convertToDate(t);
// format all dates into epoch millis
long epochMillis = date.getTime();
return Long.toString(epochMillis);
public String formatValue(T value) {
final Date date = convertToDate(value);
return Long.toString(date.getTime());
}
@Override
public T parse(String value) {
try {
long epochMillis = Long.parseLong(value);
return convertFromDate(new Date(epochMillis));
return convertFromDate(new Date(Long.parseLong(value)));
} catch (NumberFormatException e) {
Date date = Date.valueOf(value);
return convertFromDate(date);
return convertFromDate(Date.valueOf(value));
}
}
public T convertFromMillis(long systemTimeMillis) {
Date ts = new Date(systemTimeMillis);
return convertFromDate(ts);
return convertFromDate(new Date(systemTimeMillis));
}
@Override
@@ -100,11 +100,6 @@ public abstract class ScalarTypeBaseDate<T> extends ScalarTypeBase<T> {
}
}
/**
* Convert the value to ISO8601 format.
*/
protected abstract String toIsoFormat(T value);
@Override
public DocPropertyType docType() {
return DocPropertyType.DATE;
@@ -115,9 +110,7 @@ public abstract class ScalarTypeBaseDate<T> extends ScalarTypeBase<T> {
if (!dataInput.readBoolean()) {
return null;
} else {
long val = dataInput.readLong();
Date date = new Date(val);
return convertFromDate(date);
return convertFromDate(new Date(dataInput.readLong()));
}
}
@@ -127,8 +120,7 @@ public abstract class ScalarTypeBaseDate<T> extends ScalarTypeBase<T> {
dataOutput.writeBoolean(false);
} else {
dataOutput.writeBoolean(true);
Date date = convertToDate(value);
dataOutput.writeLong(date.getTime());
dataOutput.writeLong(convertToDate(value).getTime());
}
}