VB Script中需要澄清以执行某些日计算

时间:2012-08-17 06:36:06

标签: vbscript editor workflow hp-quality-center

我目前正致力于使用VB Script在HP Application Lifecycle管理工具中定义工作流脚本。

我的问题是我必须生成一个Excel图表来计算各个开发人员在特定Sprint(时间范围)中所做的努力。在生成相同的过程中,我的条件是从图表中消除周末日期(即周六和周日)。如果Sprint startdate在周末出现,则日期应自动初始化为下一个紧接的星期一,如果Sprint End日期在周末,则结束日期应显示为刚刚过去的星期五。我已经验证了这两个条件。我试图削减这两天之间的星期六和星期日。请帮我一下。如果您需要我方的任何意见,请告诉我。

1 个答案:

答案 0 :(得分:0)

@Sabaresh,我相信这就是你要找的东西。

提示:有关将Microsoft的权威WSH参考作为Windows帮助文件下载的信息,请参阅this answer

Option Explicit

Dim dCandidateDate, dActualStartDate, dActualEndDate

dCandidateDate = CDate("2012/08/18")
dActualStartDate = SprintStartDate(dCandidateDate)

dCandidateDate = CDate("2012/09/16")
dActualEndDate   = SprintEndDate(dCandidateDate)

WScript.Echo "Sprint date range: " _
       & dActualStartDate & " through " & dActualEndDate

'
' Return following Monday if dCandidateDate is
' Saturday or Sunday.
'
Function SprintStartDate(dCandidateDate)
    Dim nWeekday : nWeekday = DatePart("w", dCandidateDate)
    Select Case nWeekday
        Case 7  ' Saturday
            SprintStartDate = DateAdd("d", 2, dCandidateDate)
        Case 1  ' Sunday
            SprintStartDate = DateAdd("d", 1, dCandidateDate)
        Case Else
            SprintStartDate = dCandidateDate
    End Select
End Function

'
' Return previous Friday if dCandidateDate is
' Saturday or Sunday.
'
Function SprintEndDate(dCandidateDate)
    Dim nWeekday : nWeekday = DatePart("w", dCandidateDate)
    Select Case nWeekday
        Case 7  ' Saturday
            SprintEndDate = DateAdd("d", -1, dCandidateDate)
        Case 1  ' Sunday
            SprintEndDate = DateAdd("d", -2, dCandidateDate)
        Case Else
            SprintEndDate = dCandidateDate
    End Select
End Function