From 97ae449d18865be5c594bf1b96c44bc2536bfca3 Mon Sep 17 00:00:00 2001 From: Marc Wodahl Date: Fri, 1 Mar 2024 14:52:14 -0700 Subject: [PATCH] Trim nanoseconds in snmpTimestampFromIso --- .../src/test/java/us/dot/its/jpo/ode/snmp/SNMPTest.java | 6 ++++++ .../src/main/java/us/dot/its/jpo/ode/plugin/SNMP.java | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/jpo-ode-core/src/test/java/us/dot/its/jpo/ode/snmp/SNMPTest.java b/jpo-ode-core/src/test/java/us/dot/its/jpo/ode/snmp/SNMPTest.java index 383cb9995..9a755cb07 100644 --- a/jpo-ode-core/src/test/java/us/dot/its/jpo/ode/snmp/SNMPTest.java +++ b/jpo-ode-core/src/test/java/us/dot/its/jpo/ode/snmp/SNMPTest.java @@ -76,4 +76,10 @@ public void testSnmpTimestampFromIso() throws ParseException { String snmpTS = SNMP.snmpTimestampFromIso("2017-05-04T21:55:00-05:00"); assertEquals("07E1050415370000", snmpTS); } + + @Test + public void testSnmpTimestampFromIsoNanosecondFormat() throws ParseException { + String snmpTS = SNMP.snmpTimestampFromIso("2024-03-01T20:29:33.033Z"); + assertEquals("07E80301141D211F", snmpTS); + } } diff --git a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/SNMP.java b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/SNMP.java index 9c2c5fd66..3e22948bb 100644 --- a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/SNMP.java +++ b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/SNMP.java @@ -136,7 +136,8 @@ public static String snmpTimestampFromIso(String isoTimestamp) throws ParseExcep sb.append(String.format("%02X", zdt.getHour())); sb.append(String.format("%02X", zdt.getMinute())); sb.append(String.format("%02X", zdt.getSecond())); - sb.append(String.format("%02X", zdt.getNano())); + sb.append(String.format("%02X", zdt.getNano()).substring(0, 2)); + return sb.toString(); }