OHLCPlugInView.java: fix bug in interval parsing. test.

This commit is contained in:
2018-07-23 18:03:03 -07:00
parent 648b14eda9
commit 77dd0e2fc4
2 changed files with 29 additions and 8 deletions

View File

@ -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();
}
/**

View File

@ -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);