mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-10 21:31:53 +01:00
Forgot to test decimal negatives Signed-off-by: Gaël L'hopital <gael@lhopital.org>
This commit is contained in:
parent
abb558851f
commit
b9105bde38
@ -104,10 +104,11 @@ public class DateTimeType implements PrimitiveType, State, Command {
|
|||||||
date = parse("1970-01-01T" + zonedValue);
|
date = parse("1970-01-01T" + zonedValue);
|
||||||
} catch (DateTimeParseException timeOnlyException) {
|
} catch (DateTimeParseException timeOnlyException) {
|
||||||
try {
|
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;
|
Instant i;
|
||||||
// Assume that below 12 digits we're in seconds
|
// Assume that below 12 digits we're in seconds
|
||||||
if (zonedValue.length() < 12) {
|
if (length < 12) {
|
||||||
i = Instant.ofEpochSecond(epoch);
|
i = Instant.ofEpochSecond(epoch);
|
||||||
} else {
|
} else {
|
||||||
i = Instant.ofEpochMilli(epoch);
|
i = Instant.ofEpochMilli(epoch);
|
||||||
|
@ -121,6 +121,12 @@ public class DecimalTypeTest {
|
|||||||
public void testConversionToDateTimeType() {
|
public void testConversionToDateTimeType() {
|
||||||
assertEquals(new DateTimeType("2014-03-30T10:58:47+0000"),
|
assertEquals(new DateTimeType("2014-03-30T10:58:47+0000"),
|
||||||
new DecimalType("1396177127").as(DateTimeType.class));
|
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
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user