Jq "now" function time representation

611 views
Skip to first unread message

Pablo

unread,
Nov 28, 2023, 5:50:59 AM11/28/23
to Kogito development mailing list
Hi,
I'm using jq "now" function to complete a parameter in a Serverless Workflow.
I was expecting "now" to return an integer representing the time miliseconds Unix Epoch, but I get an exponential represented number  (1.701165821E9).
Is there any function/setting to get this as an integer?

BR

Alberto Fanjul Alonso

unread,
Nov 28, 2023, 6:26:37 AM11/28/23
to kogito-de...@googlegroups.com
Hope this helps:

from this input timers-raw.json:
```
{
  "timer-instance" : [ {
    "name" : "",
    "id" : 1,
    "timer-id" : 0,
    "activation-time" : {
  "java.util.Date" : 1701170556010
},
    "last-fire-time" : null,
    "next-fire-time" : {
  "java.util.Date" : 1701170736010
},
    "delay" : 180000,
    "period" : 0,
    "repeat-limit" : -1,
    "process-instance-id" : 1,
    "session-id" : 2
  } ]
}
```

```
jq '.["timer-instance"][] | .["activation-time"]["java.util.Date"]|=(./1000 | strflocaltime("%F %T"))|.["next-fire-time"]["java.util.Date"]|=(./1000 | strflocaltime("%F %T"))' timers-raw.json
{
  "name": "",
  "id": 1,
  "timer-id": 0,
  "activation-time": {
    "java.util.Date": "2023-11-28 12:22:36"
  },
  "last-fire-time": null,
  "next-fire-time": {
    "java.util.Date": "2023-11-28 12:25:36"
  },
  "delay": 180000,
  "period": 0,
  "repeat-limit": -1,
  "process-instance-id": 1,
  "session-id": 2
}
```

--
You received this message because you are subscribed to the Google Groups "Kogito development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kogito-developm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kogito-development/66c6047a-8488-46e9-a82f-e3561ceaf498n%40googlegroups.com.

Alberto Fanjul Alonso

unread,
Nov 28, 2023, 6:32:01 AM11/28/23
to kogito-de...@googlegroups.com
Sorry probably misunderstood the question: You just can remove precision:

$ echo '""' | jq 'now'
1701171044.935852
$ echo '""' | jq 'now|floor'
1701171046

Pablo

unread,
Nov 28, 2023, 7:11:44 AM11/28/23
to Kogito development mailing list
Thank you very much.
You are right, first example expression transforms all the  milliseconds to dates, and in my case I would need the opposite.
I tried using fromdate, todateiso8601 and then fromdateiso8601 again but logs report those functions are not available.
I already tried floor, but I get the same value as the input. Quite strange
I execute this expression not in a console but inside Serverless Workflow  filter.


For example:  timestamp: (now|floor) returns also 1.701165821E9
I don't know if it is a representation problem or what, but it does not work for me.

I could do (timestamp /1000)|floor and I get 1701165.0 but is still float and I need an integer. Anyway the time would be incorrect.
I tried round and also nearbyint and both report error in the logs.

Best regards
Reply all
Reply to author
Forward
0 new messages