I'm using a Web request to get data from another service.
The Json response look like this.
{
"result": [
{
"lastclock": "1601240174",
"lastvalue": "69.2"
},
{
"lastclock": "1601240174",
"lastvalue": "50.1"
}
]
}
lastclock is the timestamp in unix epoch time, and I like to convert this to Jira DateTime object. I tried "toDate" but did not work.
Using the Log Action, the following give no output.
{{webhookResponse.body.result.get(0).lastclock.toDate}}
Maybe I need to provide the time format to "toDate" function? But I'm not sure what the format should be.
What would be the best way to convert unix epoch seconds to Jira date time using the Automation for Jira plug-in?
Hi @Hongman Kim ,
We had the same challenge today and we were able to do a workaround by going back to 1970 and summing the milliseconds to the date you are looking for.
First, you create a variable with the 01/01/1970 date
1. Create variable
Variable name: epochDate
Smart value: 01/01/1970
Then you can use this variable to generate your dates using Epoch, in your case lastclock is returning Seconds, so you should be able to use something like below.
2. Log action
{{epochDate.toDate("dd/MM/yyyy").plusSeconds(1601240174)}}
In our case we are used Millis so it's
{{epochDate.toDate("dd/MM/yyyy").plusMillis(1601240174000)}}
You can then use this to set JIRA Fields in the Automation :D
Hope this helps!
jira smart values do not allow to use plusSeconds with another smart value though, it seems, so this might be fruitless in most cases... e.g., you can do {{epochDate.toDate("dd/MM/yyyy").plusSeconds(1601240174)}} but not a dynamic value for 1601240174 within the plusSeconds() (it seems?)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Dane Kantner , we were able to use a dynamic value in the function using a second variable, we used millis but I think this might work with Seconds.
1. Create a variable
Variable name: endDataInMillis
Smart value: {{yourSmartValueHere}}
In your action you can use the following:
{{epochDate.toDate("dd/MM/yyyy").plusMillis(endDataInMillis.asNumber)}}
It only worked when casting the variable to number using asNumber function.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thank you so much for the .asNumber, I had been trying to find if there was a need to cast the string->int for this purpose but couldn't find that ... that actually fixed it. In my case I'm actually diffing between a previously opened issue and newly opened and doing some math on that difference, so I'm adding the plusSeconds to the new create date vs 1970... I just needed the smartvariablename.asNumber for it to add the plusSeconds to that create date.
The other problem I was having with calculating that date itself was I was trying to use the lookupIssue variable to retrieve the resolutionDate field, and that isn't returned with the lookupIssues smart var. Instead I had to do a lookup for the issue I wanted, and then use a branch to do JQL search of that found lookupIssue, and that does the branch loop on that issue 2 where I can set a smart variable to capture the resolutionDate. Then outside of the branch lookup, I can use that smart var to calculate whatever and set fields in the original issue 1.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for this, it almost works but the year is displaying weird for me.
1582853854278 -- 0120-10-27T01:37:34.2+0000
First value is the raw unix timestamp, second is the end result of the comversion.
{{CallStart}} -- {{epochDate.toDate("dd/MM/yyyy").plusMillis(CallStart.asNumber)}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
never mind, I mucked up the year in the smart value. Works a treat now.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.