calculating time taken

Issue #430 resolved
Robert Anthony created an issue

Hi Fidel, I have another code question for your wonderful plugin that I've installed with a new client.

We would like to add a new date field label “Completed Date/Time”. This calculates the time when the issue was created to when it was marked as complete. For example: • Issue was created at 5PM. • Issue then was moved to “DONE” status at 8PM. • The new field “Completed Date/Time” should display: 3:00 hours So the new field indicates to us how long it took to complete the issue.

Comments (20)

  1. Fidel Castro Armario repo owner

    Hi Robert. Thanks for your words. I have some questions for you:

    1. Field Completed Date/Time is a number or a text custom field?
    2. If it's a number field, which time unit do you want to use? Minutes, Hours, Days,...?
    3. If it's a text field, do you want a format like "1 day 5 hours 12 minutes"? Something similar to Issue #319?
    4. Do you want to skip weekends when doing the calculation? I.e., from Friday to Tuesday we would only count Friday, Monday and Tuesday.
  2. Robert Anthony Account Deactivated reporter

    Hi Fidel, It would be similar to #319 as a text field, but I would prefer to skip weekends and allow day hours and minutes to be all calculated within the same field. Thanks!

  3. Fidel Castro Armario repo owner

    Use "Copy a parsed text to a field" post-function with the following configuration:

    • Target field: Completed Date/Time
    • Parsing mode: advanced
    • Text to be parsed:
    floor(subtractDatesSkippingWeekends({00112}, {00009}, LOCAL) / {DAY}) + " days " + floor(modulus(subtractDatesSkippingWeekends({00112}, {00009}, LOCAL), {DAY}) / {HOUR}) + " hours" + round(modulus(subtractDatesSkippingWeekends({00112}, {00009}, LOCAL), {HOUR}) / {MINUTE}) + " minutes"
    

    Or use the following expression if you don't want to skip weekends:

    floor(({00112} - {00009}) / {DAY}) + " days " + floor(modulus(({00112} - {00009}), {DAY}) / {HOUR}) + " hours" + round(modulus(({00112} - {00009}), {HOUR}) / {MINUTE}) + " minutes"
    

    Note that:

    • {00112} is code for numeric value of Date and time of resolution
    • {00009} is code for numeric value of Date and time of creation
    • Completed Date/Time should be a text custom field.

    You can replace {00112} with any Date-Time custom field that you set to current date and time at transition to Done status.

  4. Robert Anthony Account Deactivated reporter

    Fidel, So I copied the instructions but the custom field just displays the formula as the value when it transitions to done. I didn't replace the numeric value of the fields, that was optional right? For my situation I want the data pulled from creation to resolution so I thought the formula would be solid. I tried using both a single line and multi line text custom field, same problem. Not sure what I'm doing wrong.

  5. Fidel Castro Armario repo owner

    My bad. I have edited my previous post. You should use advanced parsing mode

  6. Robert Anthony Account Deactivated reporter

    So now im getting the following error when I try to transition to done: Bad expression in post-function "Copy a parsed text to a field". Edit post-function configuration and debug entered expression. It seems that you have tried to perform an illegal workflow operation. If you think this message is wrong, please contact your JIRA administrators.

    I have verified the only thing different is the " at the beginning of the formula, when I select advanced it puts two "' for me to paste my formula in between (I assume).

  7. Robert Anthony Account Deactivated reporter

    I have tried the formula as an exact paste, removing the first quotation and last one, now I get the following error when I try to transition: It seems that you have tried to perform an illegal workflow operation. If you think this message is wrong, please contact your JIRA administrators.

    Here is what the formula looks like: floor(subtractDatesSkippingWeekends({00112}, {00009}, LOCAL) / {DAY}) + " days " + floor(modulus(subtractDatesSkippingWeekends({00112}, {00009}, LOCAL), {DAY}) / {HOUR}) + " hours" + round(modulus(subtractDatesSkippingWeekends({00112}, {00009}, LOCAL), {HOUR}) / {MINUTE}) + " minutes"

  8. Fidel Castro Armario repo owner

    Which version of JIRA Workflow Toolbox do you have installed?

    Can you please, attach an XML export of the workflow?

  9. Robert Anthony Account Deactivated reporter

    Thanks Fidel, I can definitely put in a request, but everything is out of support with this client. Trying to convince them to update jira and relevant plugins right now, but if there is a workaround using another one of the PF's in the interim it sure would help. Any chance there is another way I can do this with the slightly older version?

  10. Fidel Castro Armario repo owner

    Sorry, Robert. The problem is that you are running the post-function on an unresolved issue, and the expression expects field "Date and time of resolution" return a value.

    I can give you an alternative expression that works also with unset "Date and time of resolution" field. Which behavior do you want in case the issue is not resolved?

    1. Return an empty string.
    2. Return "Not yet resolved issue."
    3. Do the calculation using "Current date and time" instead of "Date and time of resolution".
  11. Robert Anthony Account Deactivated reporter

    Fidel, Hmm I don't think that's the case. I've verified in the workflow that the post function above the parsed field postfunction should alter the resolution field. Is this where the bug is occurring?

    Either way I feel like solution#3 would also help.

  12. Fidel Castro Armario repo owner

    You should have Resolution field set. I have tested the expressions on JIRA 6.2.3 and JIRA Workflow Toolbox 2.2.11 and it works correctly, but when field Resolution is unset, the same error message that you are getting is shown.

    Which version of JIRA are you using?

  13. Robert Anthony Account Deactivated reporter

    I am on version 6.4.6

    Were you able to look at the workflow I attached? I believe I have the pfs in the proper order on the done transition, but maybe I'm wrong?

  14. Fidel Castro Armario repo owner

    The problem is that you are setting "Resolution" in the same transition as you are using field "Date and time of resolution", and that field will not be actually set until transition has ended. This is due to how JIRA works.

    There is a very simple solution: using "Current date and time" instead of "Date and time of resolution". Use any of the following expressions:

    • Skipping weekends:
    floor(subtractDatesSkippingWeekends({00057}, {00009}, LOCAL) / {DAY}) + " days " + floor(modulus(subtractDatesSkippingWeekends({00057}, {00009}, LOCAL), {DAY}) / {HOUR}) + " hours " + round(modulus(subtractDatesSkippingWeekends({00057}, {00009}, LOCAL), {HOUR}) / {MINUTE}) + " minutes"
    
    • Not skipping weekends:
    floor(({00057} - {00009}) / {DAY}) + " days " + floor(modulus(({00057} - {00009}), {DAY}) / {HOUR}) + " hours " + round(modulus(({00057} - {00009}), {HOUR}) / {MINUTE}) + " minutes"
    
  15. Fidel Castro Armario repo owner

    Hi @Ranthony1981,

    Since version 2.2.39, JIRA Workflow Toolbox supports Custom Schedules, and you can do all you are doing now using addTimeSkippingWeekends () and subtractDatesSkippingWeekends () functions, and much much more.

    I recommend you to take a look at it. You will be able to do amazing things using it.

  16. Log in to comment