Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion javakdb/src/main/java/com/kx/c.java
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,8 @@ void w(LocalDate d){
*/
LocalTime rt(){
int timeAsInt=ri();
return (timeAsInt==ni?LOCAL_TIME_NULL:LocalTime.ofNanoOfDay(timeAsInt*1_000_000L));
// 86,400,00 is the max ms for LocalTime (24:00:00), after that we circle back to 00:00:00
return (timeAsInt==ni?LOCAL_TIME_NULL:LocalTime.ofNanoOfDay((Math.abs(timeAsInt) % 86_400_000) * 1_000_000L));
}
/**
* Write LocalTime to serialization buffer in big endian format
Expand Down
21 changes: 21 additions & 0 deletions javakdb/src/test/java/com/kx/CTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.junit.Assert.assertTrue;

import java.io.UnsupportedEncodingException;
import java.util.UUID;
import java.util.Arrays;
import java.time.LocalTime;
Expand Down Expand Up @@ -437,6 +438,26 @@ public void testSerializeDeserializeTime()
}
}

@Test
public void testDeserializeTimeBeyond24Hours() throws c.KException, UnsupportedEncodingException {
// Serialized payload: 43:12:34.567 => 155,554,567ms
byte[] incomingMsg = new byte[]{1, 2, 0, 0, 13, 0, 0, 0, -19, 7, -109, 69, 9};
com.kx.c c = new com.kx.c();
LocalTime actual = (LocalTime) c.deserialize(incomingMsg);
LocalTime expected = LocalTime.of(19, 12, 34, 567_000_000);
Assert.assertEquals(expected, actual);
}

@Test
public void testDeserializeTimeNegative() throws c.KException, UnsupportedEncodingException {
// Serialized payload: -23:12:34.567 -> -83,554,567ms
byte[] payload = new byte[]{1, 2, 0, 0, 13, 0, 0, 0, -19, -7, 14, 5, -5};
com.kx.c c = new com.kx.c();
LocalTime actual = (LocalTime) c.deserialize(payload);
LocalTime expected = LocalTime.of(23, 12, 34, 567_000_000);
Assert.assertEquals(expected, actual);
}

@Test
public void testSerializeDeserializeInstant()
{
Expand Down