diff --git a/src/studio/kdb/K.java b/src/studio/kdb/K.java index 2e648e8..547d928 100755 --- a/src/studio/kdb/K.java +++ b/src/studio/kdb/K.java @@ -1068,7 +1068,7 @@ public StringBuilder format(StringBuilder builder, KFormatContext context) { } public Timestamp toTimestamp() { - return new Timestamp(((long) (.5 + 8.64e7 * (value + 10957)))); + return new Timestamp(Math.round(8.64e7 * (value + 10957))); } } @@ -1415,7 +1415,7 @@ public static KTimespan duration(double duration, KType unitType) { if (! NS_IN_TYPES.containsKey(unitType)) throw new IllegalArgumentException(unitType.toString() + " is not supported"); - return new KTimespan((long) (duration * NS_IN_TYPES.get(unitType))); + return new KTimespan(Math.round (duration * NS_IN_TYPES.get(unitType))); } public double toUnitValue(KType unitType) { @@ -1429,7 +1429,7 @@ public static KTimespan duration(double duration, ChronoUnit unit) { if (! NS_IN_UNITS.containsKey(unit)) throw new IllegalArgumentException("Unit " + unit.toString() + " is not supported"); - return new KTimespan((long) (duration * NS_IN_UNITS.get(unit)) ); + return new KTimespan(Math.round (duration * NS_IN_UNITS.get(unit)) ); } diff --git a/src/studio/kdb/KFormat.java b/src/studio/kdb/KFormat.java index a3bb25a..0c869ee 100644 --- a/src/studio/kdb/KFormat.java +++ b/src/studio/kdb/KFormat.java @@ -6,7 +6,6 @@ import java.text.ParsePosition; import java.time.Duration; import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; public class KFormat extends NumberFormat { @@ -58,7 +57,7 @@ public StringBuffer format(double value, StringBuffer toAppendTo, FieldPosition if (hasFraction) { LocalDateTime dateTime = ((K.Month)kValue).toLocalDateTime(); - LocalDateTime next = dateTime.plus((int)Math.signum(fraction), ChronoUnit.MONTHS); + LocalDateTime next = dateTime.plusMonths((int)Math.signum(fraction)); long days = Duration.between(dateTime, next).toDays(); long ns = (long) (Math.abs(fraction) * days * K.NS_IN_DAY); kValue = K.KTimestamp.of(dateTime).add(new K.KTimespan(ns)); diff --git a/test/studio/kdb/KTest.java b/test/studio/kdb/KTest.java index b964578..604dc56 100644 --- a/test/studio/kdb/KTest.java +++ b/test/studio/kdb/KTest.java @@ -284,7 +284,7 @@ public void testSecondToString() throws Exception { @Test public void testDatetimeToString() throws Exception { - check(new K.KDatetime(-123456.789), "1661.12.26T05:03:50.401", "1661.12.26T05:03:50.401"); + check(new K.KDatetime(-123456.789), "1661.12.26T05:03:50.400", "1661.12.26T05:03:50.400"); check(new K.KDatetime(123.456), "2000.05.03T10:56:38.400", "2000.05.03T10:56:38.400"); check(new K.KDatetime(Double.NEGATIVE_INFINITY), "-0wz", "-0wz"); check(new K.KDatetime(Double.POSITIVE_INFINITY), "0wz", "0wz");