From fb0eecdf8379b18bff3d7522cbee1cc1e9b10381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20=C3=81lvarez=20=C3=81lvarez?= Date: Tue, 3 Mar 2020 16:32:55 +0100 Subject: [PATCH] Ensure HdivReader understands both date formats (w/o date) --- .../benchmark/score/parsers/HdivReader.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/owasp/benchmark/score/parsers/HdivReader.java b/src/main/java/org/owasp/benchmark/score/parsers/HdivReader.java index 36739f0206..1e595c2f21 100644 --- a/src/main/java/org/owasp/benchmark/score/parsers/HdivReader.java +++ b/src/main/java/org/owasp/benchmark/score/parsers/HdivReader.java @@ -3,6 +3,7 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; @@ -65,14 +66,11 @@ else if (line.contains("Product version:")) { private String calculateTime(final String firstLine, final String lastLine) { try { - String start = firstLine.split(" ")[0]; - String stop = lastLine.split(" ")[0]; - SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss,SSS"); - Date startTime = sdf.parse(start); - Date stopTime = sdf.parse(stop); - long startMillis = startTime.getTime(); - long stopMillis = stopTime.getTime(); - return (stopMillis - startMillis) / 1000 + " seconds"; + try { + return calculateTime(firstLine, lastLine, 0); + } catch (ParseException e) { + return calculateTime(firstLine, lastLine, 1); + } } catch (Exception e) { e.printStackTrace(); @@ -80,6 +78,17 @@ private String calculateTime(final String firstLine, final String lastLine) { return null; } + private String calculateTime(final String firstLine, final String lastLine, final int timeColumn) throws ParseException { + String start = firstLine.split(" ")[timeColumn]; + String stop = lastLine.split(" ")[timeColumn]; + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss,SSS"); + Date startTime = sdf.parse(start); + Date stopTime = sdf.parse(stop); + long startMillis = startTime.getTime(); + long stopMillis = stopTime.getTime(); + return (stopMillis - startMillis) / 1000 + " seconds"; + } + private void process(final TestResults tr, String testNumber, final List chunk) throws Exception { for (String line : chunk) { TestCaseResult tcr = new TestCaseResult();