Hi Folks,
I have below script to calculate Working days between two custom date fields which are only date fields (NO time stamp).
Please help me to understand "where i am wrong in below script"
=================================
customfield_16160 = 12/Mar/19
customfield_16281 =20/Mar/19
Answer must be = 6 (working days)
Currently it gives 0 or Null
===============================
Script :
import com.atlassian.jira.component.ComponentAccessor
import java.sql.Timestamp
import java.time.DayOfWeek
import java.text.SimpleDateFormat;
def Plannedstartdate=ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_16160")
def dateB=ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_16281")
if (!issue.getCustomFieldValue(Plannedstartdate) || !issue.getCustomFieldValue(dateB)) {
return null
}
def startdate = (issue.getCustomFieldValue(Plannedstartdate)as Timestamp).toLocalDateTime().toLocalDate()
def enddate = (issue.getCustomFieldValue(dateB) as Timestamp).toLocalDateTime().toLocalDate()
if (!enddate.isBefore(startdate)) {
return null
}
def weekend = EnumSet.of(DayOfWeek.SATURDAY, DayOfWeek.SUNDAY)
def workingDays = 0
while (enddate.isBefore(startdate)) {
if (!(enddate.dayOfWeek in weekend)) {
workingDays += 1
}
enddate = enddate.plusDays(1)
}
workingDays
Regards,
Amar