Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Automation - Convert number to time

Csaba Vertessy
Contributor
January 31, 2024

Hello,

I'm looking for a solution to convert number to time (d/h/m/s)

I was following this article to calculate time spent in the pending status. The result is a numeric number.

Is there a way to get convert the result to d/h/m/s?

Thanks for any suggestion.

2 answers

1 accepted

2 votes
Answer accepted
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 31, 2024

Hi @Csaba Vertessy 

When using the diff() function on two date (or date / time) smart values, you may use the prettyPrint unit of measure to make that human-readable.  For example:

{{issue.created.diff(now).prettyPrint}}

https://support.atlassian.com/cloud-automation/docs/jira-smart-values-date-and-time/#Date-difference---

Kind regards,
Bill

Csaba Vertessy
Contributor
February 1, 2024

Hello Bill,

Thank you for your reply.

But I get this error:

Error rendering smart-values when executing this rule:
Too many numbers or variables: 

 

For this:


{{#=}}{{NumberOfSeconds}} + {{IF(TotalPendingSeconds,TotalPendingSeconds,0)}}{{/}}

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 1, 2024

The syntax of the if() expression you are trying is this:

{{if(someBooleanExpression, valueToReturnForTrue, valueToReturnForFalse)}}

https://support.atlassian.com/cloud-automation/docs/jira-smart-values-conditional-logic/#if

But you appear to be passing a number for the Boolean expression.

If changing that does not help, please post an image of your complete rule, images of the relevant actions / conditions / branches, and of the audit log details showing the rule execution.  Those will provide context for what you are observing.  Thanks!

Csaba Vertessy
Contributor
February 5, 2024

Hi @Bill Sheboy ,

I'm following this KB: How to use automation to get the time an issue was in a status | Jira | Atlassian Documentation

Under Saving Cumulative Time part, I'm using

{{#=}}{{NumberOfSeconds}} + {{IF(TotalPendingSeconds,TotalPendingSeconds,0)}}{{/}}

The result is in seconds. Far as I understood, prettyPrint does not work here in the expression (at leas it was empty for me).

Then I tried to create a variable, do the mat there and use Edit issue to update the field with the value and prettyPrint

image.png

image.png

image.png

If I remove prettyPrint from the math, it works:

image.png

 

Any thoughts? 

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 5, 2024

The date / time diff() function's units of measure are for date / time field differences.  They cannot operate on arbitrary number values, as created by that article's suggestions.  And so prettyPrint cannot work on just a number.

If you expect issues to only be in a status / column one time, try using just the diff on the date / time values.

But if you expect the issues to be in multiple times and want the cumulative value, as that article describes, consider either manually performing the calculations with math functions (for each unit, days, hours, minutes, and seconds) or use a marketplace addon for the reporting.

Like • Csaba Vertessy likes this
Csaba Vertessy
Contributor
February 7, 2024

Hi @Bill Sheboy ,

Thanks for the explanation, I will see how to get it work.

2 votes
Evgenii
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 31, 2024

Hi, @Csaba Vertessy 

What is original value, that you try to convert to time?
Is it numeric field, ot time duration field, like logged time?


You can use smart value math functions, to convert number to date units. Here are some examples:

Seconds

{{timetracking.timeSpentSeconds}}

Minutes

{{#=}}{{timetracking.timeSpentSeconds}} / 60{{/}}

Hours

{{#=}}{{timetracking.timeSpentSeconds}} / 3600{{/}}

Days

{{#=}}{{timetracking.timeSpentSeconds}} / 3600 / 24{{/}}
Csaba Vertessy
Contributor
January 31, 2024

Hi @Evgenii ,

The result is the diff between two transition dates.

For eg.; the result is 59,843 (in seconds).

I want to convert this to human readable value like: 0d 16h 37m ...s

Evgenii
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 31, 2024

Got it. Then you can use smart values like:

{{#=}}{{timetracking.timeSpentSeconds}} / 3600 / 24{{/}}d {{#=}}{{timetracking.timeSpentSeconds}} / 3600{{/}}h {{#=}}{{timetracking.timeSpentSeconds}} / 60{{/}}m {{timetracking.timeSpentSeconds}}s

Use your smart value instead of mine {{timetracking.timeSpentSeconds}}, which I showed for example

Csaba Vertessy
Contributor
February 5, 2024 edited

Hi @Evgenii ,

thanks for you suggestion, however, your dividing provides the same result for each math. So its not converting.

Thanks anyway, I appreciate it.

Evgenii
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 5, 2024

Dividing in 4 pieces is not a very good solution. Numbers are not round and it's required to calculate correctly hours/minutes/secons (in my example it's not made)

Try to use @Bill Sheboy advice. It must work. I made a test rule, and it shows required  formatting by default
Screenshot_20.png Screenshot_22.png

 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
atlassian, dance, gamification, badge, razzle dazzle, team '25 anaheim

Earn a one-day badge today and do the Atlazzle Dazzle! 🕺

Today only! Share what you’re the most excited about for Team ‘25 or just dance out the beginning of a new quarter with us.

Comment the post
AUG Leaders

Atlassian Community Events