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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Calculate the time issue have been created without holidys

Hi gus,

 

I want a field to calculate the time issue have been created without holidys (saturday&sunday).

But I don't kown how to do it.

 

Below is my code, but it is include holidays.

How can I  except holidays?

 

def haveBeenCreatedTime = System.currentTimeMillis() - issue.created.getTime()
return (haveBeenCreatedTime / 1000 / 3600 / 24 ) as long 

 

1 answer

1 accepted

0 votes
Answer accepted

@Harry Huang 

 

You need to use a another method to calculate the the non-working days between your start/end date then deduct the return value from "haveBeenCreatedTime"

 

in your case startcalTime = System.currentTimeMillis() , endCal = issue.created.getTime()

 


def countNonWorkingDays(def startcalTime, def endCal) {

Calendar startCal = new GregorianCalendar()
startCal.setTimeInMillis(startcalTime)
def iHolydayCnt = 0
while (startCal.getTimeInMillis() < endCal) {
if ((startCal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)
|| (startCal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY))
) {
++iHolydayCnt
}
startCal.add(Calendar.DAY_OF_YEAR, 1)
}
return iHolydayCnt
}

@Mehmet Adel Thank you for your answer, but this line will be error

2019-09-10_141942.png

def startcalTime = System.currentTimeMillis()
def endCal = issue.created.getTime()

def countNonWorkingDays(def startcalTime, def endCal) {

Calendar startCal = new GregorianCalendar()
startCal.setTimeInMillis(startcalTime)
def iHolydayCnt = 0
while (startCal.getTimeInMillis() < endCal) {
if ((startCal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) || (startCal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY))
{
++iHolydayCnt
}
startCal.add(Calendar.DAY_OF_YEAR, 1)
}
return iHolydayCnt
}

 


@Harry Huang 

please ignore the console error and use the following code as you need to call the method to get the value . 

 

def startcalTime = System.currentTimeMillis()
def endCal = issue.created.getTime()

def nonWorkingDays = countNonWorkingDays(startcalTime,endCal)

def haveBeenCreatedTime = System.currentTimeMillis() - issue.created.getTime() - nonWorkingDays*(60*60*24*1000)


def countNonWorkingDays(def startcalTime, def endCal) {

Calendar startCal = new GregorianCalendar()
startCal.setTimeInMillis(startcalTime)
def iHolydayCnt = 0
while (startCal.getTimeInMillis() < endCal) {
if ((startCal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) || (startCal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY))
{
++iHolydayCnt
}
startCal.add(Calendar.DAY_OF_YEAR, 1)
}
return iHolydayCnt
}

@Mehmet Adel Thank you for your answer again. But it seems still contain holidays

2019-09-10_150133.png

@Harry Huang 

Sorry for the confusion, in your case 

endCal = system.currentTimeMillis()

startCal = issue.created.getTime()

regards,

Finally, this code is totally achieve my requirement.

@Mehmet Adel Thanks a lot.

 

Calendar c1 = new GregorianCalendar()
c1.setTimeInMillis(issue.created.getTime())

int iHolydayCnt = 0

while(c1.getTimeInMillis() < System.currentTimeMillis() ){ 
c1.add(Calendar.DATE, 1)
if((c1.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) || (c1.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)){
++iHolydayCnt
}
}

def haveBeenCreatedTime = System.currentTimeMillis() - issue.created.getTime() - iHolydayCnt*(60*60*24*1000)

return (haveBeenCreatedTime / 1000 / 3600 / 24 ) as long

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

3,953 views 11 5
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you