From f4e1424b75aca1eaeac6eae5d1a36eebf7437af8 Mon Sep 17 00:00:00 2001 From: Eiichi Sato Date: Sat, 7 Aug 2021 19:28:08 +0900 Subject: [PATCH] now/0: add now/0 function --- .../jq/internal/functions/NowFunction.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 jackson-jq/src/main/java/net/thisptr/jackson/jq/internal/functions/NowFunction.java diff --git a/jackson-jq/src/main/java/net/thisptr/jackson/jq/internal/functions/NowFunction.java b/jackson-jq/src/main/java/net/thisptr/jackson/jq/internal/functions/NowFunction.java new file mode 100644 index 00000000..046444c7 --- /dev/null +++ b/jackson-jq/src/main/java/net/thisptr/jackson/jq/internal/functions/NowFunction.java @@ -0,0 +1,26 @@ +package net.thisptr.jackson.jq.internal.functions; + +import java.util.List; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.DoubleNode; +import com.google.auto.service.AutoService; + +import net.thisptr.jackson.jq.Expression; +import net.thisptr.jackson.jq.Function; +import net.thisptr.jackson.jq.PathOutput; +import net.thisptr.jackson.jq.Scope; +import net.thisptr.jackson.jq.Version; +import net.thisptr.jackson.jq.exception.JsonQueryException; +import net.thisptr.jackson.jq.internal.BuiltinFunction; +import net.thisptr.jackson.jq.path.Path; + +@AutoService(Function.class) +@BuiltinFunction("now/0") +public class NowFunction implements Function { + + @Override + public void apply(final Scope scope, final List args, final JsonNode in, final Path path, final PathOutput output, final Version version) throws JsonQueryException { + output.emit(new DoubleNode(System.currentTimeMillis() / 1000.0), null); + } +}