exceptionfactory commented on a change in pull request #4734:
URL: https://github.com/apache/nifi/pull/4734#discussion_r560952390



##########
File path: 
nifi-commons/nifi-record/src/main/java/org/apache/nifi/serialization/record/util/DataTypeUtils.java
##########
@@ -1085,6 +1180,31 @@ private static Object toEnum(Object value, EnumDataType 
dataType, String fieldNa
         throw new IllegalTypeConversionException("Cannot convert value [" + 
value + "] of type " + value.getClass() + " to Date for field " + fieldName);
     }
 
+    private static Date parseDate(final String string, final DateFormat 
dateFormat) throws ParseException {
+        // DateFormat.parse() creates java.util.Date with System Default Time 
Zone
+        final java.util.Date parsed = dateFormat.parse(string);
+
+        Instant parsedInstant = parsed.toInstant();
+        if (isTimeZoneAdjustmentRequired(dateFormat)) {
+            // Adjust parsed date using System Default Time Zone offset 
milliseconds when time zone format not found
+            parsedInstant = 
parsedInstant.minus(TimeZone.getDefault().getRawOffset(), ChronoUnit.MILLIS);
+        }
+
+        return new Date(parsedInstant.toEpochMilli());
+    }
+
+    private static boolean isTimeZoneAdjustmentRequired(final DateFormat 
dateFormat) {
+        boolean adjustmentRequired = false;
+
+        if (dateFormat instanceof SimpleDateFormat) {
+            final SimpleDateFormat simpleDateFormat = (SimpleDateFormat) 
dateFormat;
+            final String pattern = simpleDateFormat.toPattern();
+            adjustmentRequired = !pattern.contains(TIME_ZONE_PATTERN);

Review comment:
       Thanks, I adjusted the check to use a regular expression pattern for all 
three characters.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to