Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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
}

@Mohamed 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
}

@Mohamed 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.

@Mohamed 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
Published in Jira Service Management

JSM June Challenge #2: Share how your business teams became ITSM rockstars

For JSM June Challenge #2, share how your non-technical teams like HR, legal, marketing, finance, and beyond started using Jira Service Management! Tell us: Did they ask to start using it or...

211 views 6 7
Read article

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