Correcting Issue #1231 (#1240)

Forgot to test decimal negatives

Signed-off-by: Gaël L'hopital <gael@lhopital.org>
This commit is contained in:
Gaël L'hopital 2019-11-25 23:21:44 +01:00 committed by Kai Kreuzer
parent abb558851f
commit b9105bde38
2 changed files with 9 additions and 2 deletions

View File

@ -104,10 +104,11 @@ public class DateTimeType implements PrimitiveType, State, Command {
date = parse("1970-01-01T" + zonedValue);
} catch (DateTimeParseException timeOnlyException) {
try {
Long epoch = Long.valueOf(zonedValue);
long epoch = Double.valueOf(zonedValue).longValue();
int length = (int) (Math.log10(epoch >= 0 ? epoch : epoch * -1) + 1);
Instant i;
// Assume that below 12 digits we're in seconds
if (zonedValue.length() < 12) {
if (length < 12) {
i = Instant.ofEpochSecond(epoch);
} else {
i = Instant.ofEpochMilli(epoch);

View File

@ -121,6 +121,12 @@ public class DecimalTypeTest {
public void testConversionToDateTimeType() {
assertEquals(new DateTimeType("2014-03-30T10:58:47+0000"),
new DecimalType("1396177127").as(DateTimeType.class));
assertEquals(new DateTimeType("1969-12-31T23:59:59+0000"), new DecimalType("-1").as(DateTimeType.class));
assertEquals(new DateTimeType("1970-01-01T00:00:00+0000"), DecimalType.ZERO.as(DateTimeType.class));
assertEquals(new DateTimeType("1970-01-01T00:00:01+0000"), new DecimalType("1").as(DateTimeType.class));
assertEquals(new DateTimeType("1970-01-01T00:00:01+0000"), new DecimalType("1.0").as(DateTimeType.class));
assertEquals(new DateTimeType("1970-01-01T00:00:01+0000"), new DecimalType("1.5").as(DateTimeType.class));
assertEquals(new DateTimeType("1969-12-31T23:59:59+0000"), new DecimalType("-1.0").as(DateTimeType.class));
}
@Test