From de5c0345d825b0507beb7d21881adadb1e1994cd Mon Sep 17 00:00:00 2001 From: Sharang Gupta Date: Wed, 28 Oct 2026 23:51:43 +0000 Subject: [PATCH] Parse text TIME fractions without a double Going through Double.parseDouble truncated some fractions by a nanosecond, so '00:00:00.000065' decoded to 64999 ns. Signed-off-by: Sharang Gupta Assisted-by: Anthropic Claude (claude-opus-5-5) --- .../io/vertx/mysqlclient/impl/datatype/DataTypeCodec.java | 3 +-- .../io/vertx/tests/mysqlclient/data/DateTimeCodecTest.java | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/vertx-mysql-client/src/main/java/io/vertx/mysqlclient/impl/datatype/DataTypeCodec.java b/vertx-mysql-client/src/main/java/io/vertx/mysqlclient/impl/datatype/DataTypeCodec.java index d153e4cd57..c13ca1aefe 100644 --- a/vertx-mysql-client/src/main/java/io/vertx/mysqlclient/impl/datatype/DataTypeCodec.java +++ b/vertx-mysql-client/src/main/java/io/vertx/mysqlclient/impl/datatype/DataTypeCodec.java @@ -731,8 +731,7 @@ private static Duration textDecodeTime(int collationId, ByteBuf buffer, int inde int second = Integer.parseInt(timeElements[2].substring(0, 2)); long nanos = 0; if (timeElements[2].length() > 2) { - double fractionalSecondsPart = Double.parseDouble("0." + timeElements[2].substring(3)); - nanos = (long) (1000000000 * fractionalSecondsPart); + nanos = Long.parseLong((timeElements[2].substring(3) + "00000000").substring(0, 9)); } if (isNegative) { return Duration.ofHours(-hour).minusMinutes(minute).minusSeconds(second).minusNanos(nanos); diff --git a/vertx-mysql-client/src/test/java/io/vertx/tests/mysqlclient/data/DateTimeCodecTest.java b/vertx-mysql-client/src/test/java/io/vertx/tests/mysqlclient/data/DateTimeCodecTest.java index 062e21ef22..b33d7cea48 100644 --- a/vertx-mysql-client/src/test/java/io/vertx/tests/mysqlclient/data/DateTimeCodecTest.java +++ b/vertx-mysql-client/src/test/java/io/vertx/tests/mysqlclient/data/DateTimeCodecTest.java @@ -75,6 +75,11 @@ public void testDecodeFractionalSecondsPart(TestContext ctx) { testDecodeGeneric(ctx, "11:12:00.123456", "TIME(6)", "test_time", Duration.ofHours(11).plusMinutes(12).plusNanos(123456000)); } + @Test + public void testDecodeSmallFractionalSecondsPart(TestContext ctx) { + testDecodeGeneric(ctx, "11:12:00.000065", "TIME(6)", "test_time", Duration.ofHours(11).plusMinutes(12).plusNanos(65000)); + } + @Test public void testDecodeTimeAsLocalTimeWithFractionalSecondsPart(TestContext ctx) { testDecodeGeneric(ctx, "11:12:00.123456", "TIME(6)", row -> {