Skip to content

Commit

Permalink
Correcting Issue #1231 (#1240)
Browse files Browse the repository at this point in the history
Forgot to test decimal negatives

Signed-off-by: Gaël L'hopital <[email protected]>
  • Loading branch information
clinique authored and kaikreuzer committed Nov 25, 2019
1 parent abb5588 commit b9105bd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ public DateTimeType(String zonedValue) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ public void testConversionToHSBType() {
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
Expand Down

0 comments on commit b9105bd

Please sign in to comment.