Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How do I convert seconds to pretty print format?

Peder Alm
Contributor
November 2, 2022

Given the value of e.g. aggregatetimeoriginalestimate, how do I convert this value in seconds to a pretty print format like "2d 4h"?

2 answers

0 votes
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.
November 2, 2022

Hi @Peder Alm 

Have you tried using the diff() with prettyPrint and use a date/time value as an intermediary?

For example, diff on now and now + your field value. Maybe something like this:

{{now.diff(now.plusSeconds(issue.aggregatetimeoriginalestimate)).prettyPrint}}

 

Kind regards,
Bill

Peder Alm
Contributor
November 14, 2022

This is pretty close! But sometimes I get something like "2 hours 59 minutes 59 seconds" when I have "3h" as input. Maybe because now is called twice? What if now is just called once to a variable? Is it even possible to work with variables in this small field?

 

Also if I have "2d" as input I get "16h" as output. Can this be changed sp the output is "2d"?

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.
November 14, 2022

Maybe that is it...or it is a rounding thing caused by diff() and number representation.

Created variables sometimes work with functions...and sometimes not.  You can try it to learn if they are supported for this case.

For example:

  • create a variable named varNow set to {{now}}
  • use the variable in the expression as:
    • {{varNow.asDate.diff(varNow.asDate.plusSeconds(issue.aggregatetimeoriginalestimate)).prettyPrint}}

For the second part on 2d and 16h, I suspect that is also a rounding thing.  I would submit a support ticket to ask Atlassian for that one.

0 votes
Dan Tombs
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.
November 2, 2022

Hi @Peder Alm

Are you trying to convert the value of the aggregate into another field?

Dan

Peder Alm
Contributor
November 2, 2022

Yes, exactly! I simplified my question, but the origin of my question is mentioned in ∑original estimate ∑Time spent usage . I have calculated a time estimate value and have the result in seconds, but would like to present it in a read-only field. The value in seconds is displayed correctly in the field, but when I try to convert it and change the output using different methods, I don't get what I want, a human readable format, e.g. "2d 4h", instead of displaying seconds or hours.

Dan Tombs
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.
November 2, 2022

Ahhhh okay. Perfect, thanks for the other details, I now get what you are trying to properly achieve. The short answer is no. As of right now there is no way the automation engine can understand that 60 minutes means one hour and therefore display as 1h.

 

I tend to find that reporting in minutes is the easiest for my users followed by hours.

Peder Alm
Contributor
November 2, 2022

I had an idea that I could use the prettyPrint unit from diff() in some way. So I wanted to convert my time estimate value in seconds to a DateTime object (donät know how!) and then diff it to 0, e.g. "myTimeEstimateValueAsDateTimeObject.diff(0).prettyPrint". COuld that be a possible solution?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events