dan-s1 commented on code in PR #8332:
URL: https://github.com/apache/nifi/pull/8332#discussion_r1478500657


##########
nifi-commons/nifi-record/src/main/java/org/apache/nifi/serialization/record/field/ObjectLocalDateTimeFieldConverter.java:
##########
@@ -67,22 +70,49 @@ public LocalDateTime convertField(final Object field, final 
Optional<String> pat
                 try {
                     return LocalDateTime.parse(string, formatter);
                 } catch (final DateTimeParseException e) {
-                    throw new FieldConversionException(LocalDateTime.class, 
field, name, e);
+                    return tryParseAsNumber(string, name);
                 }
             } else {
-                try {
-                    final long number = Long.parseLong(string);
-                    final Instant instant = Instant.ofEpochMilli(number);
-                    return ofInstant(instant);
-                } catch (final NumberFormatException e) {
-                    throw new FieldConversionException(LocalDateTime.class, 
field, name, e);
-                }
+                return tryParseAsNumber(string, name);
             }
         }
 
         throw new FieldConversionException(LocalDateTime.class, field, name);
     }
 
+    private LocalDateTime tryParseAsNumber(final String value, final String 
fieldName) {
+        // If decimal, treat as a double and convert to seconds and 
nanoseconds.
+        if (value.contains(".")) {
+            final double number = Double.parseDouble(value);
+            return toLocalDateTime((long) number, (long) ((number - (long) 
number) * 1_000_000_000));

Review Comment:
   Perhaps since this is being done twice, create a reusable method e.g.
   ```
   private long convertFractionsOfSecondToNanoseconds(Number number) {
         final double fractionsOfASecond = number.doubleValue() - 
number.longValue();
         final long nanoSeconds = (long)(fractionsOfASecond *  1_000_000_000);
         return nanoSeconds;
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to