Skip to content

Commit

Permalink
decrease earliest epoch value by 3 hours query XML
Browse files Browse the repository at this point in the history
  • Loading branch information
elliVM committed Nov 14, 2024
1 parent 36d4267 commit 1551c09
Showing 1 changed file with 29 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,65 +190,62 @@ public Node visitTimeQualifier(DPLParser.TimeQualifierContext ctx) {
* @param ctx
* @return ElementNode(XML) with LE/GE unixtime
*/
private ElementNode timeQualifierEmitXml(DPLParser.TimeQualifierContext ctx) {
String op = null;
long timevalue = 0;
String value = null;
boolean isRelativeTime = false;
Token comparisonToken;
private ElementNode timeQualifierEmitXml(final DPLParser.TimeQualifierContext ctx) {
// Get specifier
// We know that 2 first children are terminals
final TerminalNode node = (TerminalNode) ctx.getChild(0);
final String nodeValue = ctx.getChild(1).getText();
final RelativeTimeParser relativeTimeParser = new RelativeTimeParser();

// Get specifier. We know that 2 first childs are terminals
// 'earliest = '
TerminalNode node = (TerminalNode) ctx.getChild(0);
value = ctx.getChild(1).getText();
Timestamp now = new Timestamp(System.currentTimeMillis());
RelativeTimeParser rtParser = new RelativeTimeParser();
// Is time given as absolute
// Try to check if it is relative and catch exception
try {
// relative time
RelativeTimestamp rtTimestamp = rtParser.parse(value); // might throw NFE if not relative timestamp
timevalue = rtTimestamp.calculate(now);
long epochValue;
try { // Try to check if it is relative
final RelativeTimestamp relativeTimestamp = relativeTimeParser.parse(nodeValue); // might throw NFE if not relative timestamp
final Timestamp now = new Timestamp(System.currentTimeMillis());
epochValue = relativeTimestamp.calculate(now);
} catch (NumberFormatException e) { // else absolute time
epochValue = this.getEpochFromString(nodeValue, catCtx.getTimeFormatString());
}
catch (NumberFormatException ne) {
// absolute time
timevalue = this.getEpochFromString(value, catCtx.getTimeFormatString());
}
// Handle date calculations
switch (node.getSymbol().getType()) {

// TODO: this is a hack to remove 3 hours from earliest value for archive
final long epochValueMinusThreeHours = epochValue - (3 * 60 * 60 * 1000); // decrease epoch by 3 hours
final Token comparisonToken;
final String op;

final int symbolType = node.getSymbol().getType();
final String symbolText = node.getSymbol().getText();
switch (symbolType) { // Handle date calculations
case DPLLexer.EARLIEST: {
op = "earliest";
comparisonToken = new Token(Type.GE);

startTime = timevalue;
startTime = epochValueMinusThreeHours; // use -3 hours
break;
}
case DPLLexer.INDEX_EARLIEST: {
op = "index_earliest";
comparisonToken = new Token(Type.GE);
startTime = timevalue;
startTime = epochValueMinusThreeHours; // use -3 hours
break;
}
case DPLLexer.LATEST: {
op = "latest";
comparisonToken = new Token(Type.LE);
endTime = timevalue;
endTime = epochValue;
break;
}
case DPLLexer.INDEX_LATEST: {
op = "index_latest";
comparisonToken = new Token(Type.LE);
endTime = timevalue;
endTime = epochValue;
break;
}
default: {
throw new RuntimeException("TimeQualifier <" + node.getSymbol().getText() + "> not implemented yet.");
throw new RuntimeException("TimeQualifier <" + symbolText + "> not implemented yet.");
}
}

Element el = doc.createElement(op);
final Element el = doc.createElement(op);
el.setAttribute("operation", comparisonToken.toString());
el.setAttribute("value", Long.toString(timevalue));
el.setAttribute("value", Long.toString(epochValue));
return new ElementNode(el);
}

Expand Down

0 comments on commit 1551c09

Please sign in to comment.