Hi Brains Trust,
I've been working at this for over a day now, even having run it past chatgpt without much joy.
I'm trying to calculate the project hours remaining by calculating all of the original estimated at the task level, then deducting that from the time spent at the task level. Then rolling this figure up to display in a custom field at the epic level.
This is a formula that calculates the time remaining on a task by:
Taking the original estimated time for the task (which can be given in weeks, days, hours, and minutes),
Converting all those time units into seconds,
Doing the same for the time already spent on the task (also in weeks, days, hours, and minutes),
Subtracting the time spent (in seconds) from the original estimate (in seconds).
- Converting this to hours, then writing back to the epic in a custom field.
So basically:
It looks at the original estimate like "2w 3d 4h 15m" and converts everything to seconds.
It looks at the time spent like "1w 1d 2h 30m" and also converts to seconds.
Then it subtracts time spent from the original estimate to find how many seconds are left.
If any part (weeks, days, hours, minutes) is missing, it treats that as zero.
The challenge is that the the characters found in the time amounts, (ie. w, d, h, m). These need to be accounted for so that the calculation works.
Here's what I have so far (I haven't yet divided the entire calc by 3600 yet as I want to see what's going on first):
{{#=}}
(
(
{{#if(issue.timetracking.originalEstimate.match("([0-9]+)w") != null)}}
{{issue.timetracking.originalEstimate.match("([0-9]+)w").get(0).replaceAll("[^0-9]", "").asNumber}}
{{else}}0{{/}} * 604800 + <!-- weeks to seconds -->
{{#if(issue.timetracking.originalEstimate.match("([0-9]+)d") != null)}}
{{issue.timetracking.originalEstimate.match("([0-9]+)d").get(0).replaceAll("[^0-9]", "").asNumber}}
{{else}}0{{/}} * 86400 + <!-- days to seconds -->
{{#if(issue.timetracking.originalEstimate.match("([0-9]+)h") != null)}}
{{issue.timetracking.originalEstimate.match("([0-9]+)h").get(0).replaceAll("[^0-9]", "").asNumber}}
{{else}}0{{/}} * 3600 + <!-- hours to seconds -->
{{#if(issue.timetracking.originalEstimate.match("([0-9]+)m") != null)}}
{{issue.timetracking.originalEstimate.match("([0-9]+)m").get(0).replaceAll("[^0-9]", "").asNumber}}
{{else}}0{{/}} * 60 <!-- minutes to seconds -->
)
-
(
{{#if(issue.timetracking.timeSpent.match("([0-9]+)w") != null)}}
{{issue.timetracking.timeSpent.match("([0-9]+)w").get(0).replaceAll("[^0-9]", "").asNumber}}
{{else}}0{{/}} * 604800 + <!-- weeks to seconds -->
{{#if(issue.timetracking.timeSpent.match("([0-9]+)d") != null)}}
{{issue.timetracking.timeSpent.match("([0-9]+)d").get(0).replaceAll("[^0-9]", "").asNumber}}
{{else}}0{{/}} * 86400 + <!-- days to seconds -->
{{#if(issue.timetracking.timeSpent.match("([0-9]+)h") != null)}}
{{issue.timetracking.timeSpent.match("([0-9]+)h").get(0).replaceAll("[^0-9]", "").asNumber}}
{{else}}0{{/}} * 3600 + <!-- hours to seconds -->
{{#if(issue.timetracking.timeSpent.match("([0-9]+)m") != null)}}
{{issue.timetracking.timeSpent.match("([0-9]+)m").get(0).replaceAll("[^0-9]", "").asNumber}}
{{else}}0{{/}} * 60 <!-- minutes to seconds -->
)
)
{{/=}}