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
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
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry for the confusion, in your case
endCal = system.currentTimeMillis()
startCal = issue.created.getTime()
regards,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.