Skip to content

Commit

Permalink
format timespan with 0D (even for 0 days)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmipt committed Dec 13, 2024
1 parent 0d3ba1e commit c0a8d22
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/studio/kdb/K.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
8 changes: 4 additions & 4 deletions test/studio/kdb/KTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c0a8d22

Please sign in to comment.