Time duration format

Issue #461 resolved
mgorokhova created an issue

Hello!

I use post-function "Mathematical or date-time expression calculator" for calculating time between transitions. But I don't want to log work and use field "Time Spent". I want to use custom field and get time in minutes. How can I do it, using JIRA Workflow Toolbox? And second question: Is any chance to get time between transitions in pretty duration format (for example, 1d 2h ).

Thank you!

Comments (5)

  1. Fidel Castro Armario repo owner

    Hi,

    In order to calculate the time between the execution of 2 different transitions (let's say "Transition A" and "Transition B"), and store the obtained value in minutes into a Number custom field you can use the following solution:

    1) Create Number custom field called "Time elapsed in minutes", where we will store the value obtained.

    2) Create a Date-Time Picker custom field called "Transition A Execution Time"

    3) Insert post-function "Mathematical and date-time expression calculator" into transition "Transition A" (i.e., the transition executed earlier) using the following configuration:

    • Target field: Transition A Execution Time
    • Formula:
    {00057}
    

    4) Insert post-function "Mathematical and date-time expression calculator" into transition "Transition B" (i.e., the transition executed later) using the following configuration:

    • Target field: select a Time elapsed in minutes
    • Formula:
    ({00057} - {aaaaa}) / {MINUTE}
    

    replacing aaaaa with the field code of Transition A Execution Time custom field.

    You can also represent the time duration between the 2 transition executions as a string in pretty format. To do it, also insert "Copy a parsed text to a field" post-function into "Transition B" with the following configuration:

    • Target field: a text custom field
    • Parsing mode: advanced
    • Text to be parsed:
    (floor(({00057} - {aaaaa}) / {DAY}) > 0 ? floor(({00057} - {aaaaa}) / {DAY}) + "d " : "") + (floor(modulus(({00057} - {aaaaa}), {DAY}) / {HOUR}) > 0 ? floor(modulus(({00057} - {aaaaa}), {DAY}) / {HOUR}) + "h " : "") + (round(modulus(({00057} - {aaaaa}), {HOUR}) / {MINUTE}) > 0 ? round(modulus(({00057} - {aaaaa}), {HOUR}) / {MINUTE}) + "m" : "")
    

    replacing aaaaa with the field code of Transition A Execution Time custom field.

  2. Fidel Castro Armario repo owner

    Hi @mgorokhova,

    Since version 2.2.39 you will be able to implement that same use case but considering only the time in a particular work-schedule. It's explained in detail in the following thread of the Help Forum, and at Automatic Work Log With Start and Stop Work Transitions.

    In your particular case you should use the following formulas:

    1) To obtain the number of minutes use "Mathematical and date-time expression calculator" post-function with the following formula:

    timeDifference({00057}, {aaaaa}, "my_work_schedule", LOCAL) / {MINUTE}
    

    2) To obtain the normal time duration as a text use "Copy a parsed text to a field" post-function with the following expression in advanced parsing mode:

    shortFormatDuration(timeDifference({00057}, {aaaaa}, "my_work_schedule", LOCAL))
    

    3) To obtain the work time duration as a text use "Copy a parsed text to a field" post-function with the following expression in advanced parsing mode:

    shortFormatWorkDuration(timeDifference({00057}, {aaaaa}, "my_work_schedule", LOCAL))
    

    Work duration uses the workday and workweek defined at time tracking configuration, instead of 24 hours per day and 7 days per week.

    Your custom work schedule is defined at Administration > Add-ons > JIRA WORKFLOW TOOLBOX > Schedule using SDG.

  3. Fidel Castro Armario repo owner

    Issue #678 explains how to deal with old issues where customfield "Transition A Execution Time" is not set.

  4. Log in to comment