You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2020/09/30 17:09:41 UTC

[GitHub] [kafka] mjsax commented on a change in pull request #9255: KAFKA-6585: Consolidate duplicated logic on reset tools

mjsax commented on a change in pull request #9255:
URL: https://github.com/apache/kafka/pull/9255#discussion_r497669807



##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,34 @@ private static byte checkRange(final byte i) {
         }
         return map;
     }
+
+    /**
+     * Convert an ISO8601 based timestamp to an epoch value
+     * @param timestamp to be converted
+     * @return epoch value of a given timestamp
+     * @throws ParseException for timestamp that doesn't follow ISO8601 format
+     */
+    public static long getDateTime(String timestamp) throws ParseException {
+        final String[] timestampParts = timestamp.split("T");
+        if (timestampParts.length < 2) {
+            throw new ParseException("Error parsing timestamp. It does not contain a 'T' according to ISO8601 format", timestamp.length());
+        }
+
+        final String secondPart = timestampParts[1];
+        if (secondPart == null || secondPart.isEmpty()) {
+            throw new ParseException("Error parsing timestamp. Time part after 'T' is null or empty", timestamp.length());
+        }
+
+        if (!(secondPart.contains("+") || secondPart.contains("-") || secondPart.contains("Z"))) {

Review comment:
       I was looking up the format in more detail and understand now what going on. The code does not seem to be ideal IMHO, but no need to change it in this PR.




----------------------------------------------------------------
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:
users@infra.apache.org