[Minor] Changed DateParameter to use ZonedDateTime internally
This commit is contained in:
parent
acc2cd2fc0
commit
599ec9b3b2
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.model.parameter;
|
package li.strolch.model.parameter;
|
||||||
|
|
||||||
import static li.strolch.utils.iso8601.ISO8601.EMPTY_VALUE;
|
import static li.strolch.utils.iso8601.ISO8601.EMPTY_VALUE_ZONED_DATE;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
|
@ -32,7 +32,7 @@ import li.strolch.utils.iso8601.ISO8601;
|
||||||
*/
|
*/
|
||||||
public class DateParameter extends AbstractParameter<Date> {
|
public class DateParameter extends AbstractParameter<Date> {
|
||||||
|
|
||||||
private Date value;
|
private ZonedDateTime value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Empty constructor
|
* Empty constructor
|
||||||
|
@ -64,20 +64,21 @@ public class DateParameter extends AbstractParameter<Date> {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public Date getValue() {
|
public Date getValue() {
|
||||||
return this.value;
|
return Date.from(this.value.toInstant());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValue(Date value) {
|
public void setValue(Date value) {
|
||||||
assertNotReadonly();
|
assertNotReadonly();
|
||||||
validateValue(value);
|
validateValue(value);
|
||||||
this.value = value;
|
this.value = ZonedDateTime.ofInstant(value.toInstant(), ZoneId.systemDefault());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValueFrom(Parameter<Date> parameter) {
|
public void setValueFrom(Parameter<Date> parameter) {
|
||||||
assertNotReadonly();
|
assertNotReadonly();
|
||||||
this.value = parameter.getValue();
|
DateParameter other = (DateParameter) parameter;
|
||||||
|
this.value = other.toZonedDateTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -93,46 +94,47 @@ public class DateParameter extends AbstractParameter<Date> {
|
||||||
@Override
|
@Override
|
||||||
public void clear() {
|
public void clear() {
|
||||||
assertNotReadonly();
|
assertNotReadonly();
|
||||||
this.value = EMPTY_VALUE;
|
this.value = EMPTY_VALUE_ZONED_DATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return this.value.equals(EMPTY_VALUE);
|
return this.value.equals(EMPTY_VALUE_ZONED_DATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEqualTo(Parameter<Date> otherValue) {
|
public boolean isEqualTo(Parameter<Date> otherValue) {
|
||||||
return this.value.equals(otherValue.getValue());
|
DateParameter other = (DateParameter) otherValue;
|
||||||
|
return this.value.equals(other.toZonedDateTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEqualTo(Date otherValue) {
|
public boolean isEqualTo(Date otherValue) {
|
||||||
return this.value.equals(otherValue);
|
return getValue().equals(otherValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEqualTo(LocalDateTime otherValue) {
|
public boolean isEqualTo(LocalDateTime otherValue) {
|
||||||
return this.value.equals(Date.from(otherValue.atZone(ZoneId.systemDefault()).toInstant()));
|
return this.value.toLocalDateTime().equals(otherValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEqualTo(ZonedDateTime otherValue) {
|
public boolean isEqualTo(ZonedDateTime otherValue) {
|
||||||
return this.value.equals(Date.from(otherValue.toInstant()));
|
return this.value.equals(otherValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZonedDateTime toZonedDateTime() {
|
public ZonedDateTime toZonedDateTime() {
|
||||||
return ZonedDateTime.ofInstant(this.value.toInstant(), ZoneId.systemDefault());
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalDateTime toLocalDateTime() {
|
public LocalDateTime toLocalDateTime() {
|
||||||
return LocalDateTime.ofInstant(this.value.toInstant(), ZoneId.systemDefault());
|
return this.value.toLocalDateTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setValueFromLocalDateTime(LocalDateTime localDateTime) {
|
public void setValueFromLocalDateTime(LocalDateTime localDateTime) {
|
||||||
this.value = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
|
this.value = localDateTime.atZone(ZoneId.systemDefault());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setValueFromZonedDateTime(ZonedDateTime zonedDateTime) {
|
public void setValueFromZonedDateTime(ZonedDateTime zonedDateTime) {
|
||||||
this.value = Date.from(zonedDateTime.toInstant());
|
this.value = zonedDateTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -151,7 +153,7 @@ public class DateParameter extends AbstractParameter<Date> {
|
||||||
|
|
||||||
super.fillClone(clone);
|
super.fillClone(clone);
|
||||||
|
|
||||||
clone.setValue(this.value);
|
clone.setValueFromZonedDateTime(this.value);
|
||||||
|
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,8 @@ public class ISO8601 implements DateFormat {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ISO8601.class);
|
private static final Logger logger = LoggerFactory.getLogger(ISO8601.class);
|
||||||
|
|
||||||
public static final Date EMPTY_VALUE = parseToDate("-");
|
public static final Date EMPTY_VALUE = parseToDate("-");
|
||||||
|
public static final ZonedDateTime EMPTY_VALUE_ZONED_DATE = ZonedDateTime
|
||||||
|
.ofInstant(EMPTY_VALUE.toInstant(), ZoneId.systemDefault());
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String format(long timePoint) {
|
public String format(long timePoint) {
|
||||||
|
|
Loading…
Reference in New Issue