If you are writing a class (e.g. called TimeUtils.groovy) and put it insrc/groovy/utils
Then add something that does this as a static method:
package utils
class TimeUtils {
static Integer calcPercentComplete(hoursComp, hoursReq) {
Integer result = ( hoursComp / hoursReq ) * 100.0
result < 0 ? 0 : result > 100 ? 100 : result
}
}
Then you can call:
def perc = utils.TimeUtils.calcPercentComplete( 8, 24 )
From anywhere in your code
source
share