OHLCPlugInView.java: fix bug in interval parsing. test.
This commit is contained in:
@ -78,7 +78,15 @@ public class OHLCPlugInView extends ViewSupport {
|
|||||||
private Duration parseInterval(ExprNode interval) {
|
private Duration parseInterval(ExprNode interval) {
|
||||||
ExprEvaluator evaluator = interval.getForge().getExprEvaluator();
|
ExprEvaluator evaluator = interval.getForge().getExprEvaluator();
|
||||||
String intervalStr = (String)evaluator.evaluate(null, true, agentContext);
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -43,14 +43,27 @@ public class OHLCPlugInViewTest {
|
|||||||
|
|
||||||
expected += ".000Z";
|
expected += ".000Z";
|
||||||
|
|
||||||
log.info(" duration: {}", interval);
|
// log.info(" duration: {}", interval);
|
||||||
log.info(" cur time: {}", dateFormatter.print(currentTime));
|
// log.info(" cur time: {}", dateFormatter.print(currentTime));
|
||||||
log.info("start time: {}", start);
|
// log.info("start time: {}", start);
|
||||||
log.info(" expected: {}", expected);
|
// log.info(" expected: {}", expected);
|
||||||
|
|
||||||
//assertEquals(interval.toString(), l.longValue(), Instant.parse("2018-05-15T13:23:00").getMillis());
|
//assertEquals(interval.toString(), l.longValue(), Instant.parse("2018-05-15T13:23:00").getMillis());
|
||||||
assertEquals(interval.toString(), expected, start);
|
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) {
|
private static Long makeWindowStartTime(Long timestamp, Duration interval) {
|
||||||
long today = getDayStart(timestamp);
|
long today = getDayStart(timestamp);
|
||||||
|
|||||||
Reference in New Issue
Block a user