From b36190df2425574ed2cf3d542a189abac6f96e78 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 5 Mar 2024 14:21:05 +0100 Subject: [PATCH] Remove useless warning about rounding We are warning when we round the time -- assuming we have millisecond-precision time. We have switched to nanosecond-precision in commit efe35f12ce37107c814a5d8bb245e5f9ed9ba073, hence this warning is completely superfluous. JIRA: NETCONF-1262 Change-Id: I76377a078d13c9256ae55bc41439a1ff2bc24564 Signed-off-by: Robert Varga --- .../api/messages/NotificationMessage.java | 26 +------------------ .../api/messages/NetconfMessageTest.java | 14 ++++++++++ 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/protocol/netconf-api/src/main/java/org/opendaylight/netconf/api/messages/NotificationMessage.java b/protocol/netconf-api/src/main/java/org/opendaylight/netconf/api/messages/NotificationMessage.java index 6afae02e7d..802f12c04e 100644 --- a/protocol/netconf-api/src/main/java/org/opendaylight/netconf/api/messages/NotificationMessage.java +++ b/protocol/netconf-api/src/main/java/org/opendaylight/netconf/api/messages/NotificationMessage.java @@ -73,31 +73,7 @@ public final class NotificationMessage extends NetconfMessage { */ public static final Function RFC3339_DATE_PARSER = time -> { try { - final var localDateTime = ZonedDateTime.parse(time, DATE_TIME_FORMATTER); - final int startAt = 0; - final var parsed = DATE_TIME_FORMATTER.parse(time, new ParsePosition(startAt)); - final int nanoOfSecond = getFieldFromTemporalAccessor(parsed, ChronoField.NANO_OF_SECOND); - final long reminder = nanoOfSecond % 1000000; - - // Log warn in case we rounded the fraction of a second. We need to create a string from the - // value that was cut. Example -> 1.123750 -> Value that was cut 75 - if (reminder != 0) { - final var reminderBuilder = new StringBuilder(String.valueOf(reminder)); - - //add zeros in case we have number like 123056 to make sure 056 is displayed - while (reminderBuilder.length() < 6) { - reminderBuilder.insert(0, '0'); - } - - //delete zeros from end to make sure that number like 1.123750 will show value cut 75. - while (reminderBuilder.charAt(reminderBuilder.length() - 1) == '0') { - reminderBuilder.deleteCharAt(reminderBuilder.length() - 1); - } - LOG.warn("Fraction of second is cut to three digits. Value that was cut {}", - reminderBuilder.toString()); - } - - return Instant.from(localDateTime); + return ZonedDateTime.parse(time, DATE_TIME_FORMATTER).toInstant(); } catch (DateTimeParseException exception) { final var res = handlePotentialLeapSecond(time); if (res != null) { diff --git a/protocol/netconf-api/src/test/java/org/opendaylight/netconf/api/messages/NetconfMessageTest.java b/protocol/netconf-api/src/test/java/org/opendaylight/netconf/api/messages/NetconfMessageTest.java index 86bc60010d..435404a341 100644 --- a/protocol/netconf-api/src/test/java/org/opendaylight/netconf/api/messages/NetconfMessageTest.java +++ b/protocol/netconf-api/src/test/java/org/opendaylight/netconf/api/messages/NetconfMessageTest.java @@ -49,6 +49,20 @@ class NetconfMessageTest { """, msg.toString()); } + @Test + void testOfNotificationNanos() throws Exception { + final var eventTime = Instant.ofEpochSecond(42, 123456789); + final var expected = NotificationMessage.ofNotificationContent(getTestElement(), eventTime); + final var msg = assertInstanceOf(NotificationMessage.class, NetconfMessage.of(expected.getDocument())); + assertEquals(""" + + + 1970-01-01T00:00:42.123456789Z + + """, msg.toString()); + assertEquals(eventTime, msg.getEventTime()); + } + @Test void testOfRpc() throws Exception { final var expected = RpcMessage.ofOperation(MESSAGE_ID, getTestElement()); -- 2.36.6