maximo中的自动化脚本,如何在没有周末和假期的情况下计算2个日期之间的天数?

时间:2018-03-28 14:03:41

标签: jython maximo

maximo中的自动化脚本,如何在没有周末和假期的情况下计算2个日期之间的天数? 我可以数天,并删除星期日和星期六,但假期呢? 在Maximo目前的日历应用程序中,所有假期都存在。我如何在jython脚本中使用它?

1 个答案:

答案 0 :(得分:0)

确定。我做到了。 Maximo有“非工作时间”表,它包含日历应用程序中的所有假期。 所以,我在maximo中为自动化脚本编写了这个jython脚本。它返回2个日期之间的工作日数。

#********************* 
def getDateDiff(start, finish):
    calStart=0
    calStart=Calendar.getInstance()
    calStart.setTime(start)
    calFinish=0
    calFinish=Calendar.getInstance()
    calFinish.setTime(finish)
    daysDiff=0 
    str1=str(0)
    cS=None    
    if calStart.getTime()<calFinish.getTime():
        while calStart.getTime()<=calFinish.getTime():        
            if calStart.get(Calendar.DAY_OF_WEEK) !=1 and calStart.get(Calendar.DAY_OF_WEEK) !=7:
                cS = SimpleDateFormat("dd.MM.yyyy").format(calStart.getTime())            
                myMXServer = MXServer.getMXServer()
                userInfo = mbo.getThisMboSet().getUserInfo()
                nwSet= myMXServer.getMboSet("NONWORKTIME", userInfo)
                nwSetWhere = 'to_date( \''+cS+'\' , \'dd.mm.yyyy\' ) >= startdate and to_date(\''+cS+'\' , \'dd.mm.yyyy\' ) <=enddate'
                nwSet.setWhere(nwSetWhere)
                nwSet.reset()
                if nwSet.count() ==0:
                    daysDiff = daysDiff+1
            calStart.add(Calendar.DATE, 1)     
    else:
        while calFinish.getTime()<=calStart.getTime():        
            if calFinish.get(Calendar.DAY_OF_WEEK) !=1 and calFinish.get(Calendar.DAY_OF_WEEK) !=7:
                cS = SimpleDateFormat("dd.MM.yyyy").format(calFinish.getTime())            
                myMXServer = MXServer.getMXServer()
                userInfo = mbo.getThisMboSet().getUserInfo()
                nwSet= myMXServer.getMboSet("NONWORKTIME", userInfo)
                nwSetWhere = 'to_date( \''+cS+'\' , \'dd.mm.yyyy\' ) >= startdate and to_date(\''+cS+'\' , \'dd.mm.yyyy\' ) <=enddate'
                nwSet.setWhere(nwSetWhere)
                nwSet.reset()
                if nwSet.count() ==0:
                    daysDiff = daysDiff-1
            calFinish.add(Calendar.DATE, 1)         
    return str(daysDiff)
#**********************
daysDiffernce = getDateDiff(plandate, factdate)