Skip to content

Commit

Permalink
Handling Date and Datetimes, WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
joleaf committed Aug 16, 2024
1 parent 9ce813e commit 8170895
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
11 changes: 9 additions & 2 deletions DmnEvaluator/src/main/java/de/joleaf/dmn/evaluate/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
import org.camunda.bpm.dmn.engine.*;
import org.camunda.bpm.engine.variable.VariableMap;
import org.camunda.bpm.engine.variable.impl.VariableMapImpl;
import org.camunda.bpm.engine.variable.impl.value.PrimitiveTypeValueImpl;

import java.io.FileInputStream;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -41,9 +46,11 @@ public static void main(String[] args) {
String value = args[i + 1];
String type = args[i + 2];
if ("number".equals(type)) {
variables.put(key, Double.parseDouble(value));
variables.putValueTyped(key, new PrimitiveTypeValueImpl.DoubleValueImpl(Double.parseDouble(value)));
} else if ("boolean".equals(type)) {
variables.put(key, Boolean.parseBoolean(value));
variables.putValueTyped(key, new PrimitiveTypeValueImpl.BooleanValueImpl(Boolean.parseBoolean(value)));
} else if ("datetime".equals(type)) {
variables.put(key, new PrimitiveTypeValueImpl.DateValueImpl(Date.from(ZonedDateTime.parse(value).toInstant())));
} else {
variables.put(key, value);
}
Expand Down
9 changes: 8 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ export default class ObsidianDmnEvalPlugin extends Plugin {
}
for (const [key, value] of Object.entries(parameters.variables)) {
if (value !== undefined && value !== null) {
dmnParams += ' "' + key + '" "' + value.toString() + '" "' + typeof value + '"';
let pValue = value.toString();
let type: string = typeof value;
let isDate = !isNaN(Date.parse(value.toString()));
if (type != "number" && isDate) {
type = "datetime";
pValue = new Date(value).toISOString();
}
dmnParams += ' "' + key + '" "' + pValue + '" "' + type + '"';
}
}
let jarPath = this.getJarPath();
Expand Down

0 comments on commit 8170895

Please sign in to comment.