From c0a8d222586f98da2db0724cd2e3657b56ddbf7c Mon Sep 17 00:00:00 2001 From: dzmipt Date: Fri, 13 Dec 2024 16:41:03 +0100 Subject: [PATCH] format timespan with 0D (even for 0 days) --- src/studio/kdb/K.java | 5 ++--- test/studio/kdb/KTest.java | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/studio/kdb/K.java b/src/studio/kdb/K.java index 547d928..0df5f86 100755 --- a/src/studio/kdb/K.java +++ b/src/studio/kdb/K.java @@ -1464,9 +1464,8 @@ public StringBuilder format(StringBuilder builder, KFormatContext context) { jj = -jj; builder.append("-"); } - int d = ((int) (jj / NS_IN_DAY)); - if (d != 0) builder.append(d).append("D"); - builder.append(i2((int) ((jj % NS_IN_DAY) / 3600000000000L))) + builder.append((int) (jj / NS_IN_DAY)).append("D"). + append(i2((int) ((jj % NS_IN_DAY) / 3600000000000L))) .append(":").append(i2((int) ((jj % 3600000000000L) / 60000000000L))) .append(":").append(i2((int) ((jj % 60000000000L) / 1000000000L))) .append(".").append(nsFormatter.format((int) (jj % 1000000000L))); diff --git a/test/studio/kdb/KTest.java b/test/studio/kdb/KTest.java index 604dc56..f4f048d 100644 --- a/test/studio/kdb/KTest.java +++ b/test/studio/kdb/KTest.java @@ -184,15 +184,15 @@ public void testTimestampToString() throws Exception { @Test public void testTimespanToString() throws Exception { check(new K.KTimespan(-765432123456789l), "-8D20:37:12.123456789", "-8D20:37:12.123456789"); - check(new K.KTimespan(123456), "00:00:00.000123456", "00:00:00.000123456"); + check(new K.KTimespan(123456), "0D00:00:00.000123456", "0D00:00:00.000123456"); check(new K.KTimespan(-Long.MAX_VALUE), "-0Wn", "-0Wn"); check(new K.KTimespan(Long. MAX_VALUE), "0Wn", "0Wn"); check(new K.KTimespan(Long.MIN_VALUE), "0Nn", "0Nn"); - check(new K.KTimespanVector(-10, 10, 3), "-00:00:00.000000010 00:00:00.000000010 00:00:00.000000003", "-00:00:00.000000010 00:00:00.000000010 00:00:00.000000003"); + check(new K.KTimespanVector(-10, 10, 3), "-0D00:00:00.000000010 0D00:00:00.000000010 0D00:00:00.000000003", "-0D00:00:00.000000010 0D00:00:00.000000010 0D00:00:00.000000003"); check(new K.KTimespanVector(), "`timespan$()", "`timespan$()"); - check(new K.KTimespanVector(0), "enlist 00:00:00.000000000", "enlist 00:00:00.000000000"); - check(new K.KTimespanVector(5, Long.MIN_VALUE, Long.MAX_VALUE, -Long.MAX_VALUE), "00:00:00.000000005 0Nn 0Wn -0Wn", "00:00:00.000000005 0Nn 0Wn -0Wn"); + check(new K.KTimespanVector(0), "enlist 0D00:00:00.000000000", "enlist 0D00:00:00.000000000"); + check(new K.KTimespanVector(5, Long.MIN_VALUE, Long.MAX_VALUE, -Long.MAX_VALUE), "0D00:00:00.000000005 0Nn 0Wn -0Wn", "0D00:00:00.000000005 0Nn 0Wn -0Wn"); } @Test