diff --git a/src/main/java/ats/plugin/OHLCPlugInView.java b/src/main/java/ats/plugin/OHLCPlugInView.java index 936d125..8f55cae 100644 --- a/src/main/java/ats/plugin/OHLCPlugInView.java +++ b/src/main/java/ats/plugin/OHLCPlugInView.java @@ -34,9 +34,9 @@ public class OHLCPlugInView extends ViewSupport { private static final Logger log = LoggerFactory.getLogger(OHLCPlugInView.class); private static final int LATE_EVENT_SLACK_SECONDS = 5; private static final PeriodFormatter periodFormatter = new PeriodFormatterBuilder() - .appendDays().appendSuffix("d ") - .appendHours().appendSuffix("h ") - .appendMinutes().appendSuffix("m ") + .appendDays().appendSuffix("d") + .appendHours().appendSuffix("h") + .appendMinutes().appendSuffix("m") .appendSeconds().appendSuffix("s") .toFormatter(); @@ -78,7 +78,15 @@ public class OHLCPlugInView extends ViewSupport { private Duration parseInterval(ExprNode interval) { ExprEvaluator evaluator = interval.getForge().getExprEvaluator(); String intervalStr = (String)evaluator.evaluate(null, true, agentContext); - return periodFormatter.parsePeriod(intervalStr).toStandardDuration(); + return parseInterval(intervalStr); + } + + /** + * Return the time period specified by the given string. + */ + public static Duration parseInterval(String interval) { + interval = interval.replaceAll("\\s+",""); + return periodFormatter.parsePeriod(interval).toStandardDuration(); } /** diff --git a/src/test/java/ats/plugin/OHLCPlugInViewTest.java b/src/test/java/ats/plugin/OHLCPlugInViewTest.java index 37b4f7e..d17cb03 100644 --- a/src/test/java/ats/plugin/OHLCPlugInViewTest.java +++ b/src/test/java/ats/plugin/OHLCPlugInViewTest.java @@ -43,14 +43,27 @@ public class OHLCPlugInViewTest { expected += ".000Z"; - log.info(" duration: {}", interval); - log.info(" cur time: {}", dateFormatter.print(currentTime)); - log.info("start time: {}", start); - log.info(" expected: {}", expected); + // log.info(" duration: {}", interval); + // log.info(" cur time: {}", dateFormatter.print(currentTime)); + // log.info("start time: {}", start); + // log.info(" expected: {}", expected); //assertEquals(interval.toString(), l.longValue(), Instant.parse("2018-05-15T13:23:00").getMillis()); assertEquals(interval.toString(), expected, start); } + + @Test + public void testParseInterval() { + assertParseInterval("4s", new Duration(4 * 1000)); + assertParseInterval("4m", new Duration(4 * 60 * 1000)); + assertParseInterval("1m5s", new Duration(65 * 1000)); + assertParseInterval("1m 5s", new Duration(65 * 1000)); + } + + private void assertParseInterval(String str, Duration expected) { + assertEquals(OHLCPlugInView.parseInterval(str), expected); + } + /* private static Long makeWindowStartTime(Long timestamp, Duration interval) { long today = getDayStart(timestamp);